-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_state.ml
229 lines (170 loc) · 6.97 KB
/
test_state.ml
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
open Gamestate
(* =============================================================================
* TESTING SUITE for Game State
============================================================================= *)
(*
Unless otherwise noted, test cases operate by default on a 4x4 grid.
*)
(* =============================================================================
* Reusable Variables
============================================================================= *)
let pl1 = Player1
let pl2 = Player2
(* -----------------------------------------------------------------------------
* Reusable Variables - Row Setup
----------------------------------------------------------------------------- *)
let rw_empty = [
(Water, Empty); (Water, Empty); (Water, Empty); (Water, Empty)
]
let rw_miss = [
(Water, Miss); (Water, Miss); (Water, Miss); (Water, Miss)
]
let rw_miss_fst = [
(Water, Miss); (Water, Empty); (Water, Empty); (Water, Empty)
]
let rw_empty_ship = [
(ShipPart(Cruiser), Empty); (ShipPart(Cruiser), Empty); (ShipPart(Cruiser), Empty);
(ShipPart(Jetski), Empty)
]
let rw_hit = [
(ShipPart(Cruiser), Hit); (ShipPart(Cruiser), Hit); (ShipPart(Cruiser), Hit);
(ShipPart(Jetski), Hit)
]
let rw_hit_lst = [
(ShipPart(Cruiser), Empty); (ShipPart(Cruiser), Empty); (ShipPart(Cruiser), Empty);
(ShipPart(Jetski), Hit)
]
let rw_mix = [
(Water, Empty); (Water, Miss);
(ShipPart(Patrol), Hit); (ShipPart(Patrol), Empty)
]
let rw_empty_str = "----"
let rw_miss_str = "oooo"
let rw_miss_fst_str = "o---"
let rw_hit_str = "XXXX"
let rw_hit_lst_str = "###X"
let rw_mix_str = "-oX#"
let rw_hit_lst_str_public = "---X"
let rw_mix_str_public = "-oX-"
(* -----------------------------------------------------------------------------
* Reusable Variables - Grid Setup
----------------------------------------------------------------------------- *)
let gr_empty = [rw_empty; rw_empty; rw_empty; rw_empty]
let gr_miss_fst = [rw_miss_fst; rw_empty; rw_empty; rw_empty]
let gr_miss_fst_row = [rw_miss; rw_empty; rw_empty; rw_empty]
let gr_hit_lst = [rw_empty; rw_empty; rw_empty; rw_hit_lst]
let gr_miss_row = [rw_empty; rw_miss; rw_empty; rw_hit]
let gr_hit_row = [rw_empty; rw_empty; rw_hit; rw_empty]
let gr_mix = [rw_miss_fst; rw_empty; rw_mix; rw_hit_lst]
let gr_miss_hit_empty = [rw_miss_fst; rw_hit_lst; rw_empty; rw_mix]
let gr_empty_ship = [rw_empty_ship; rw_empty; rw_empty_ship; rw_empty]
(* "----\n----\n----\n----\n" *)
let gr_empty_str =
rw_empty_str ^ "\n" ^
rw_empty_str ^ "\n" ^
rw_empty_str ^ "\n" ^
rw_empty_str ^ "\n"
(* "o---\n----\n----\n----\n" *)
let gr_miss_fst_str =
rw_miss_fst_str ^ "\n" ^
rw_empty_str ^ "\n" ^
rw_empty_str ^ "\n" ^
rw_empty_str ^ "\n"
(* "oooo\n----\n----\n----\n" *)
let gr_miss_fst_row_str =
rw_miss_str ^ "\n" ^
rw_empty_str ^ "\n" ^
rw_empty_str ^ "\n" ^
rw_empty_str ^ "\n"
(* "----\n----\n----\n###X\n" *)
let gr_hit_lst_str =
rw_empty_str ^ "\n" ^
rw_empty_str ^ "\n" ^
rw_empty_str ^ "\n" ^
rw_hit_lst_str ^ "\n"
(* "----\noooo\n----\n----\n" *)
let gr_miss_row_str =
rw_empty_str ^ "\n" ^
rw_miss_str ^ "\n" ^
rw_empty_str ^ "\n" ^
rw_empty_str ^ "\n"
(* "----\n----\nXXXX\n----\n" *)
let gr_hit_row_str =
rw_empty_str ^ "\n" ^
rw_empty_str ^ "\n" ^
rw_hit_str ^ "\n" ^
rw_empty_str ^ "\n"
(* "o---\n----\n-oX#\n###X\n" *)
let gr_mix_str =
rw_miss_fst_str ^ "\n" ^
rw_empty_str ^ "\n" ^
rw_mix_str ^ "\n" ^
rw_hit_lst_str ^ "\n"
(* -----------------------------------------------------------------------------
* Reusable Variables - Side Setup
----------------------------------------------------------------------------- *)
let sd_empty = {board = gr_empty; ships = [Jetski]}
let sd_miss_fst = {board = gr_miss_fst; ships = [Jetski]}
let sd_hit_lst = {board = gr_hit_lst; ships = [Jetski]}
let sd_miss_row = {board = gr_miss_row; ships = [Jetski]}
let sd_hit_row = {board = gr_hit_row; ships = [Jetski; Cruiser]}
let sd_mix = {board = gr_mix; ships = [Jetski; Cruiser]}
let sd_hit_row_new = {board = gr_miss_hit_empty; ships = [Jetski; Cruiser]}
let sd_mix_new = {board = gr_mix; ships = [Jetski; Cruiser]}
(* =============================================================================
* TEST - Display Gamestate
============================================================================= *)
TEST = display_gamestate (sd_empty, sd_empty) pl1 true false = gr_empty_str
TEST = display_gamestate (sd_empty, sd_empty) pl2 true false = gr_empty_str
TEST = display_gamestate (sd_empty, sd_mix) pl1 true false = gr_empty_str
TEST = display_gamestate (sd_empty, sd_mix) pl2 true false = gr_mix_str
TEST = display_gamestate (sd_miss_fst, sd_hit_lst) pl1 true false = gr_miss_fst_str
TEST = display_gamestate (sd_miss_fst, sd_hit_lst) pl2 true false = gr_hit_lst_str
TEST = display_gamestate (sd_miss_row, sd_hit_row) pl2 true false = gr_hit_row_str
TEST = display_gamestate (sd_empty, sd_hit_lst) pl1 false false
= "----\n----\n----\n---X\n"
TEST = display_gamestate (sd_empty, sd_mix) pl1 false false
= "o---\n----\n-oX-\n---X\n"
TEST = display_gamestate (sd_hit_lst, sd_empty) pl2 false false
= "----\n----\n----\n---X\n"
TEST = display_gamestate (sd_mix, sd_empty) pl2 false false
= "o---\n----\n-oX-\n---X\n"
(* =============================================================================
* TEST - Victory Check
============================================================================= *)
TEST = victory (sd_hit_row_new, sd_mix_new) = None
TEST = victory (sd_hit_row_new, sd_hit_row_new) = None
TEST = victory (sd_hit_row_new, sd_hit_row) = Some (Player1)
TEST = victory (sd_hit_row, sd_hit_row_new) = Some (Player2)
(* =============================================================================
* TEST - Turn
============================================================================= *)
let c = (sd_empty, sd_empty)
let (b,c) = turn c ('a',0) Player1
TEST = b = Some Miss
TEST = display_gamestate c pl2 true false = gr_miss_fst_str
TEST = display_gamestate c pl1 true false = gr_empty_str
let (b,c) = turn c ('a', 0) Player1
TEST = b = Some Empty
TEST = display_gamestate c pl2 true false = gr_miss_fst_str
TEST = display_gamestate c pl1 true false = gr_empty_str
let (b,c) = turn c ('a',1) Player1
let (b,c) = turn c ('a',2) Player1
let (b,c) = turn c ('a',3) Player1
TEST = b = Some Miss
TEST = display_gamestate c pl2 true false = gr_miss_fst_row_str
TEST = display_gamestate c pl1 true false = gr_empty_str
let sd_empty_ship = {board = gr_empty_ship; ships = [Jetski; Cruiser]}
let c = (sd_empty, sd_empty_ship)
let (b,c) = turn c ('a',0) Player1
TEST = b = Some Hit
TEST = display_gamestate c pl2 true false = "X###\n----\n####\n----\n"
let (b,c) = turn c ('a',1) Player1
let (b,c) = turn c ('a',2) Player1
let (b,c) = turn c ('a',3) Player1
let (b,c) = turn c ('b',0) Player1
let (b,c) = turn c ('b',1) Player1
let (b,c) = turn c ('b',2) Player1
let (b,c) = turn c ('b',3) Player1
TEST = b = Some Miss
TEST = display_gamestate c pl2 true false = "XXXX\noooo\n####\n----\n"