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:
parent
9cf20bb8ab
commit
5e629e9e93
8 changed files with 655 additions and 196 deletions
|
|
@ -2,6 +2,7 @@ package rules
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
@ -177,3 +178,94 @@ func TestRoyalDamageNextTurn(t *testing.T) {
|
|||
require.Equal(t, Point{9, 0}, next.Snakes[0].Body[0])
|
||||
require.Equal(t, 20, len(next.Hazards))
|
||||
}
|
||||
|
||||
// Checks that hazards get placed
|
||||
// also that:
|
||||
// - snakes move properly
|
||||
// - snake gets health from eating
|
||||
// - food gets consumed
|
||||
// - health is decreased
|
||||
var royaleCaseHazardsPlaced = gameTestCase{
|
||||
"Royale Case Hazards Placed",
|
||||
&BoardState{
|
||||
Width: 10,
|
||||
Height: 10,
|
||||
Snakes: []Snake{
|
||||
{
|
||||
ID: "one",
|
||||
Body: []Point{{1, 1}, {1, 2}},
|
||||
Health: 100,
|
||||
},
|
||||
{
|
||||
ID: "two",
|
||||
Body: []Point{{3, 4}, {3, 3}},
|
||||
Health: 100,
|
||||
},
|
||||
{
|
||||
ID: "three",
|
||||
Body: []Point{},
|
||||
Health: 100,
|
||||
EliminatedCause: EliminatedByOutOfBounds,
|
||||
},
|
||||
},
|
||||
Food: []Point{{0, 0}, {1, 0}},
|
||||
Hazards: []Point{},
|
||||
},
|
||||
[]SnakeMove{
|
||||
{ID: "one", Move: MoveDown},
|
||||
{ID: "two", Move: MoveUp},
|
||||
{ID: "three", Move: MoveLeft}, // Should be ignored
|
||||
},
|
||||
nil,
|
||||
&BoardState{
|
||||
Width: 10,
|
||||
Height: 10,
|
||||
Snakes: []Snake{
|
||||
{
|
||||
ID: "one",
|
||||
Body: []Point{{1, 0}, {1, 1}, {1, 1}},
|
||||
Health: 100,
|
||||
},
|
||||
{
|
||||
ID: "two",
|
||||
Body: []Point{{3, 5}, {3, 4}},
|
||||
Health: 99,
|
||||
},
|
||||
{
|
||||
ID: "three",
|
||||
Body: []Point{},
|
||||
Health: 100,
|
||||
EliminatedCause: EliminatedByOutOfBounds,
|
||||
},
|
||||
},
|
||||
Food: []Point{{0, 0}},
|
||||
Hazards: []Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 2, Y: 0}, {X: 3, Y: 0}, {X: 4, Y: 0}, {X: 5, Y: 0}, {X: 6, Y: 0}, {X: 7, Y: 0}, {X: 8, Y: 0}, {X: 9, Y: 0}},
|
||||
},
|
||||
}
|
||||
|
||||
func TestRoyaleCreateNextBoardState(t *testing.T) {
|
||||
// add expected hazards to the standard cases that need them
|
||||
s1 := standardCaseMoveEatAndGrow.clone()
|
||||
s1.expectedState.Hazards = []Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 2, Y: 0}, {X: 3, Y: 0}, {X: 4, Y: 0}, {X: 5, Y: 0}, {X: 6, Y: 0}, {X: 7, Y: 0}, {X: 8, Y: 0}, {X: 9, Y: 0}}
|
||||
s2 := standardMoveAndCollideMAD.clone()
|
||||
s2.expectedState.Hazards = []Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 2, Y: 0}, {X: 3, Y: 0}, {X: 4, Y: 0}, {X: 5, Y: 0}, {X: 6, Y: 0}, {X: 7, Y: 0}, {X: 8, Y: 0}, {X: 9, Y: 0}}
|
||||
|
||||
cases := []gameTestCase{
|
||||
// inherits these test cases from standard
|
||||
standardCaseErrNoMoveFound,
|
||||
standardCaseErrZeroLengthSnake,
|
||||
*s1,
|
||||
*s2,
|
||||
royaleCaseHazardsPlaced,
|
||||
}
|
||||
r := RoyaleRuleset{
|
||||
StandardRuleset: StandardRuleset{
|
||||
HazardDamagePerTurn: 1,
|
||||
},
|
||||
ShrinkEveryNTurns: 1,
|
||||
}
|
||||
rand.Seed(0)
|
||||
for _, gc := range cases {
|
||||
gc.requireValidNextState(t, &r)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue