fibs/board_test.go

65 lines
1.2 KiB
Go

package fibs
import (
"fmt"
"testing"
)
func TestBoard_GetValidMoves(t *testing.T) {
client := NewClient("", "", "")
b := NewBoard(client)
b.v[StatePlayerColor] = 1
b.v[StateTurn] = 1
b.v[StateDirection] = -1
b.v[StateBoardSpace0+11] = 3
b.v[StateBoardSpace0+9] = 7
b.v[StateBoardSpace0+13] = -4
b.v[StateBoardSpace0+24] = -3
b.v[StatePlayerBar] = 1
testCases := []struct {
roll [2]int
from int
moves []int
}{
{
roll: [2]int{1, 5},
from: 25,
moves: []int{19, 20},
},
{
roll: [2]int{1, 5},
from: 1,
moves: []int{},
},
}
for _, c := range testCases {
c := c
t.Run(fmt.Sprintf("With-%d-%d-From-%s", c.roll[0], c.roll[1], fmt.Sprintf("%02d", c.from)), func(t *testing.T) {
b.v[StatePlayerDice1], b.v[StatePlayerDice2] = c.roll[0], c.roll[1]
b.Draw()
validMoves := b.GetValidMoves(c.from)
for i := range validMoves {
if !equalInts(validMoves[i], c.moves) {
t.Errorf("unexpected valid moves: expected %+v, got %+v\n%s", c.moves, validMoves, b.Render())
}
}
})
}
}
func equalInts(a, b []int) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}