-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathengine_test.go
More file actions
73 lines (58 loc) · 1.95 KB
/
engine_test.go
File metadata and controls
73 lines (58 loc) · 1.95 KB
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
package gogo
import (
"fmt"
"testing"
)
func TestEmptyBoardAcceptsMoves(t *testing.T) {
myMove := genMove(1, 1, PlayerWhite)
emptyBoard := newBoard(19)
newBoard, err := emptyBoard.performMove(myMove)
if err != nil {
t.Errorf("Should not have received an error when placing simple positions.")
}
if newBoard.Positions[1][1] != PlayerWhite {
t.Errorf("Putting a white stone at 1,1 should result in a board with that stone in place.")
}
for r := range newBoard.Positions {
for c := range newBoard.Positions[r] {
if r != 1 && c != 1 {
if newBoard.Positions[r][c] != EmptyPosition {
t.Errorf("Encountered non-empty board position when it should have been empty.")
}
}
}
}
}
// Ensure board retains state between moves.
func TestBoardRemembersMultipleMoves(t *testing.T) {
moveA := genMove(1, 1, PlayerBlack)
moveB := genMove(2, 2, PlayerWhite)
moveC := genMove(3, 3, PlayerBlack)
emptyBoard := newBoard(19)
newBoard, _ := emptyBoard.performMove(moveA)
newBoard, _ = newBoard.performMove(moveB)
newBoard, _ = newBoard.performMove(moveC)
if newBoard.Positions[1][1] != PlayerBlack {
t.Errorf("Expected black stone at 1,1 and it wasn't there.")
}
if newBoard.Positions[2][2] != PlayerWhite {
t.Errorf("Expected white stone at 1,1 and it wasn't there.")
}
if newBoard.Positions[3][3] != PlayerBlack {
t.Errorf("Expected black stone at 3,3 and it wasn't there.")
}
}
func TestCannotPlayOnOccupiedPosition(t *testing.T) {
myMove := genMove(5, 5, PlayerWhite)
emptyBoard := newBoard(19)
emptyBoard.Positions[5][5] = PlayerBlack
_, err := emptyBoard.performMove(myMove)
expectedError := fmt.Sprintf(RulesFailureSpaceOccupied, myMove)
if err == nil {
t.Errorf("GoGo should have prevented a move onto an occupied position, but didn't return an error.")
} else {
if err.Error() != expectedError {
t.Errorf("Expected error '%s' but instead got '%s' when playing on an occupied position.", expectedError, err.Error())
}
}
}