...
1 package fibs
2
3 import (
4 "fmt"
5 "testing"
6 )
7
8 func TestBoard_GetValidMoves(t *testing.T) {
9 client := NewClient("", "", "")
10
11 b := NewBoard(client)
12
13 b.v[StatePlayerColor] = 1
14 b.v[StateTurn] = 1
15 b.v[StateDirection] = -1
16 b.v[StateBoardSpace0+11] = 3
17 b.v[StateBoardSpace0+9] = 7
18 b.v[StateBoardSpace0+13] = -4
19 b.v[StateBoardSpace0+24] = -3
20 b.v[StatePlayerBar] = 1
21
22 testCases := []struct {
23 roll [2]int
24 from int
25 moves []int
26 }{
27 {
28 roll: [2]int{1, 5},
29 from: 25,
30 moves: []int{19, 20},
31 },
32 {
33 roll: [2]int{1, 5},
34 from: 1,
35 moves: []int{},
36 },
37 }
38 for _, c := range testCases {
39 c := c
40 t.Run(fmt.Sprintf("With-%d-%d-From-%s", c.roll[0], c.roll[1], fmt.Sprintf("%02d", c.from)), func(t *testing.T) {
41 b.v[StatePlayerDice1], b.v[StatePlayerDice2] = c.roll[0], c.roll[1]
42 b.Draw()
43
44 validMoves := b.GetValidMoves(c.from)
45 for i := range validMoves {
46 if !equalInts(validMoves[i], c.moves) {
47 t.Errorf("unexpected valid moves: expected %+v, got %+v\n%s", c.moves, validMoves, b.Render())
48 }
49 }
50 })
51 }
52 }
53
54 func equalInts(a, b []int) bool {
55 if len(a) != len(b) {
56 return false
57 }
58 for i := range a {
59 if a[i] != b[i] {
60 return false
61 }
62 }
63 return true
64 }
65
View as plain text