-
Notifications
You must be signed in to change notification settings - Fork 3
/
util_test.go
83 lines (73 loc) · 1.97 KB
/
util_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"testing"
)
const MAP_WIDTH = 3
func GetSnakeOne() SnakeInfo {
return SnakeInfo{
Name: "1",
Points: 0,
TailProtectedForGameTicks: 0,
Positions: []int{TranslateCoordinate(Coordinate{X: 1, Y: 1}, MAP_WIDTH)},
Id: "1",
}
}
func GetSnakeTwo() SnakeInfo {
return SnakeInfo{
Name: "2",
Points: 0,
TailProtectedForGameTicks: 0,
Positions: []int{TranslateCoordinate(Coordinate{X: 1, Y: 2}, MAP_WIDTH)},
Id: "2",
}
}
// The map used for testing, 1 and 2 represents the snakes
//yx012
//0 F
//1 11#
//2 2
func GetTestMap() Map {
return Map{
Width: MAP_WIDTH,
Height: MAP_WIDTH,
WorldTick: 0,
SnakeInfos: []SnakeInfo{GetSnakeOne(), GetSnakeTwo()},
FoodPositions: []int{TranslateCoordinate(Coordinate{X: 1, Y: 0}, MAP_WIDTH)},
ObstaclePositions: []int{TranslateCoordinate(Coordinate{X: 2, Y: 1}, MAP_WIDTH)},
}
}
func TestSnakeCanBeFoundById(t *testing.T) {
m := GetTestMap()
id := GetSnakeOne().Id
found_id := m.GetSnakeById(id).Id
if id != found_id {
t.Error("Expected ", id, "found ", found_id)
}
}
func TestCanNotMoveToWalls(t *testing.T) {
m := GetTestMap()
id := GetSnakeTwo().Id
if m.CanSnakeMoveInDirection(id, Down) {
t.Error("Expected snake to not be able to move to walls")
}
}
func TestCanNotMoveToObstacles(t *testing.T) {
m := GetTestMap()
for _, obstaclePos := range m.ObstaclePositions {
coord := TranslatePosition(obstaclePos, MAP_WIDTH)
if m.GetTileAt(coord).IsMovable() {
t.Error("Expected obstacles not to be movable to, yet could move to", coord)
}
}
}
func TestCanNotMoveToSnakes(t *testing.T) {
m := GetTestMap()
for _, snakeInfo := range m.SnakeInfos {
for _, snakePos := range snakeInfo.Positions {
coord := TranslatePosition(snakePos, MAP_WIDTH)
if m.GetTileAt(coord).IsMovable() {
t.Error("Expected snakes not to be movable to, yet could move to", coord)
}
}
}
}