You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.1 KiB
63 lines
1.1 KiB
package main |
|
|
|
import ( |
|
"fmt" |
|
"testing" |
|
) |
|
|
|
func TestBoard_GetValidMoves(t *testing.T) { |
|
client := NewClient("", "") |
|
|
|
board = NewBoard(client) |
|
|
|
b := board |
|
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.playerDice = c.roll |
|
b.Update() |
|
|
|
validMoves := board.GetValidMoves(c.from) |
|
if !equalInts(validMoves, c.moves) { |
|
t.Errorf("unexpected valid moves: expected %+v, got %+v\n%s", c.moves, validMoves, b.GetBytes(true)) |
|
} |
|
}) |
|
} |
|
} |
|
|
|
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 |
|
}
|
|
|