DEV-765 add some additional tests (#65)

Adds additional test coverage. Re-uses standard test cases where possible and added a few additional cases specific to some modes.
This commit is contained in:
Torben 2022-03-15 16:41:39 -07:00 committed by GitHub
parent 9cf20bb8ab
commit 5e629e9e93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 655 additions and 196 deletions

View file

@ -55,3 +55,57 @@ func TestSoloIsGameOver(t *testing.T) {
require.Equal(t, test.Expected, actual)
}
}
// Checks that a single snake doesn't end the game
// also that:
// - snake moves okay
// - food gets consumed
// - snake grows and gets health from food
var soloCaseNotOver = gameTestCase{
"Solo Case Game Not Over",
&BoardState{
Width: 10,
Height: 10,
Snakes: []Snake{
{
ID: "one",
Body: []Point{{1, 1}, {1, 2}},
Health: 100,
},
},
Food: []Point{{0, 0}, {1, 0}},
Hazards: []Point{},
},
[]SnakeMove{
{ID: "one", Move: MoveDown},
},
nil,
&BoardState{
Width: 10,
Height: 10,
Snakes: []Snake{
{
ID: "one",
Body: []Point{{1, 0}, {1, 1}, {1, 1}},
Health: 100,
},
},
Food: []Point{{0, 0}},
Hazards: []Point{},
},
}
func TestSoloCreateNextBoardState(t *testing.T) {
cases := []gameTestCase{
// inherits these test cases from standard
standardCaseErrNoMoveFound,
standardCaseErrZeroLengthSnake,
standardCaseMoveEatAndGrow,
standardMoveAndCollideMAD,
soloCaseNotOver,
}
r := SoloRuleset{}
for _, gc := range cases {
gc.requireValidNextState(t, &r)
}
}