-
Notifications
You must be signed in to change notification settings - Fork 0
/
Board_test.hws
80 lines (63 loc) · 2.52 KB
/
Board_test.hws
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
@INCLUDE "Board.hws"
@INCLUDE "GameData.hws"
Function TestBoardCreate()
Local Board = Board:New()
Assert(Board.width = 19)
Assert(Board.height = 19)
EndFunction
Function TestNewBoardHasNoStones()
Local Board = Board:New()
Assert(Board:StonesPlaced() = 0)
EndFunction
Function TestCanAddStonesInBounds()
Local Board = Board:New()
Board:Place(1, 1, #PLAYER_WHITE)
Assert(Board:StonesPlaced() = 1)
Assert(Board:Get(1, 1) = #PLAYER_WHITE)
Board:Place(Board.width-1, Board.height-1, #PLAYER_BLACK)
Assert(Board:StonesPlaced() = 2)
Assert(Board:Get(Board.width-1, Board.height-1) = #PLAYER_BLACK)
EndFunction
Function TestKnowsAboutEmptyIntersections()
Local Board = Board:New()
Assert(Board:Get(0, 1) = #PLAYER_EMPTY)
Board:Place(0, 1, #PLAYER_WHITE)
Assert(Board:Get(0, 1) = #PLAYER_WHITE)
Board:Place(1, 1, #PLAYER_WHITE)
Assert(Board:Get(1, 1) = #PLAYER_WHITE)
EndFunction
Function TestCannotAddToOccupiedIntersection()
Local Board = Board:New()
Board:Place(0, 1, #PLAYER_WHITE)
Assert(Board:Place(0, 1, #PLAYER_WHITE) = #BOARDERROR_SPACEOCCUPIED)
Assert(Board:Place(0, 1, #PLAYER_BLACK) = #BOARDERROR_SPACEOCCUPIED)
EndFunction
Function TestCannotPlaceStonesOutsideBounds()
Local Board = Board:New()
Assert(Board:Place(-1, -1, #PLAYER_WHITE) = #BOARDERROR_BADLOCATION)
Assert(Board:Place(Board.width, Board.height, #PLAYER_WHITE) = #BOARDERROR_BADLOCATION)
Assert(Board:Place(0, -1, #PLAYER_WHITE) = #BOARDERROR_BADLOCATION)
Assert(Board:Place(0, Board.height, #PLAYER_WHITE) = #BOARDERROR_BADLOCATION)
Assert(Board:Place(-1, 0, #PLAYER_WHITE) = #BOARDERROR_BADLOCATION)
Assert(Board:Place(Board.width, 0, #PLAYER_WHITE) = #BOARDERROR_BADLOCATION)
Assert(Board:StonesPlaced() = 0)
EndFunction
Function TestAddStonesInSameColButDifferentRow()
Local Board = Board:New()
Assert(Board:Place(1,1,#PLAYER_WHITE) = #BOARDERROR_OK)
Assert(Board:Get(1,1) = #PLAYER_WHITE)
Assert(Board:Place(1,2,#PLAYER_BLACK) = #BOARDERROR_OK)
Assert(Board:Get(1,2) = #PLAYER_BLACK)
Board = Board:New()
Assert(Board:Place(1,1,#PLAYER_WHITE) = #BOARDERROR_OK)
Assert(Board:Place(1,2,#PLAYER_BLACK) = #BOARDERROR_OK)
Assert(Board:Get(1,1) = #PLAYER_WHITE)
Assert(Board:Get(1,2) = #PLAYER_BLACK)
EndFunction
TestBoardCreate()
TestNewBoardHasNoStones()
TestCanAddStonesInBounds()
TestKnowsAboutEmptyIntersections()
TestCannotAddToOccupiedIntersection()
TestCannotPlaceStonesOutsideBounds()
TestAddStonesInSameColButDifferentRow()