2021-07-02 20:00:19 -07:00
|
|
|
package commands
|
|
|
|
|
|
|
|
|
|
import (
|
2021-08-17 16:47:06 -07:00
|
|
|
"testing"
|
|
|
|
|
|
2021-07-02 20:00:19 -07:00
|
|
|
"github.com/BattlesnakeOfficial/rules"
|
2021-11-25 14:07:56 -08:00
|
|
|
"github.com/BattlesnakeOfficial/rules/test"
|
2021-07-02 20:00:19 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestGetIndividualBoardStateForSnake(t *testing.T) {
|
|
|
|
|
s1 := rules.Snake{ID: "one", Body: []rules.Point{{X: 3, Y: 3}}}
|
|
|
|
|
s2 := rules.Snake{ID: "two", Body: []rules.Point{{X: 4, Y: 3}}}
|
|
|
|
|
state := &rules.BoardState{
|
|
|
|
|
Height: 11,
|
|
|
|
|
Width: 11,
|
|
|
|
|
Snakes: []rules.Snake{s1, s2},
|
|
|
|
|
}
|
2021-11-25 14:07:56 -08:00
|
|
|
s1State := SnakeState{
|
|
|
|
|
ID: "one",
|
|
|
|
|
Name: "ONE",
|
|
|
|
|
URL: "http://example1.com",
|
|
|
|
|
Head: "safe",
|
|
|
|
|
Tail: "curled",
|
|
|
|
|
Color: "#123456",
|
|
|
|
|
}
|
|
|
|
|
s2State := SnakeState{
|
|
|
|
|
ID: "two",
|
|
|
|
|
Name: "TWO",
|
|
|
|
|
URL: "http://example2.com",
|
|
|
|
|
Head: "silly",
|
|
|
|
|
Tail: "bolt",
|
|
|
|
|
Color: "#654321",
|
|
|
|
|
}
|
|
|
|
|
snakeStates := map[string]SnakeState{
|
|
|
|
|
s1State.ID: s1State,
|
|
|
|
|
s2State.ID: s2State,
|
|
|
|
|
}
|
2021-12-02 18:59:20 +01:00
|
|
|
snakeRequest := getIndividualBoardStateForSnake(state, s1State, snakeStates, &rules.StandardRuleset{})
|
|
|
|
|
requestBody := serialiseSnakeRequest(snakeRequest)
|
2021-07-02 20:00:19 -07:00
|
|
|
|
2021-11-25 14:07:56 -08:00
|
|
|
test.RequireJSONMatchesFixture(t, "testdata/snake_request_body.json", string(requestBody))
|
2021-07-02 20:00:19 -07:00
|
|
|
}
|