-
Notifications
You must be signed in to change notification settings - Fork 1
/
computerTest.ml
286 lines (233 loc) · 7.03 KB
/
computerTest.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
open OUnit2
open Card
open Player
open State
open Computer
open Yojson.Basic.Util
(** Test suite for the Computer module *)
(** [action_test name g c] is true when the card output by the computer
action in game [g] is the same as the card [c], false otherwise. *)
let action_test name g c =
name >:: fun _ -> assert_equal c (snd (action g))
(** [action_test name g c] is true when the card output by the computer
action in game [g] is the same as a draw 4 card, false otherwise. *)
let action_draw4_test name g =
name >:: fun _ ->
let dp c = match snd c with None -> -1 | Some c -> draw_penalty c in
assert_equal 4 (dp (action g))
(** [action_test name g c] is true when the card output by the computer
action in game [g] is the same as a swap card [c], false otherwise. *)
let action_swap_test name g c =
name >:: fun _ ->
let swap_bool card =
match card with
| None -> false
| Some c -> (
match actions c with
| { skip = _; reverse = _; swap = true, id; change_color = _ }
->
(* print_string (string_of_int id); *) true
| _ -> false)
in
assert_equal (swap_bool c) (swap_bool (snd (action g)))
(*********************** create game g *************************)
let std_deck = standard_cards
(*** cards ***)
let red0 =
List.filter
(fun x ->
color x = R
&& digit x = Some 0
&& actions x
= {
skip = false;
reverse = false;
swap = (false, -1);
change_color = false;
}
&& draw_penalty x = 0)
std_deck
|> List.hd
let red1 =
List.filter (fun x -> color x = R && digit x = Some 1) std_deck
|> List.hd
let red2 =
List.filter (fun x -> color x = R && digit x = Some 2) std_deck
|> List.hd
let red3 =
List.filter (fun x -> color x = R && digit x = Some 3) std_deck
|> List.hd
let red4 =
List.filter (fun x -> color x = R && digit x = Some 4) std_deck
|> List.hd
let red5 =
List.filter (fun x -> color x = R && digit x = Some 5) std_deck
|> List.hd
let red6 =
List.filter (fun x -> color x = R && digit x = Some 6) std_deck
|> List.hd
let red7 =
List.filter (fun x -> color x = R && digit x = Some 7) std_deck
|> List.hd
let blue0 =
List.filter
(fun x ->
color x = B
&& digit x = Some 0
&& actions x
= {
skip = false;
reverse = false;
swap = (false, -1);
change_color = false;
}
&& draw_penalty x = 0)
std_deck
|> List.hd
let blue1 =
List.filter (fun x -> color x = B && digit x = Some 1) std_deck
|> List.hd
let blue2 =
List.filter (fun x -> color x = B && digit x = Some 2) std_deck
|> List.hd
let blue3 =
List.filter (fun x -> color x = B && digit x = Some 3) std_deck
|> List.hd
let blue4 =
List.filter (fun x -> color x = B && digit x = Some 4) std_deck
|> List.hd
let blue5 =
List.filter (fun x -> color x = B && digit x = Some 5) std_deck
|> List.hd
let blue6 =
List.filter (fun x -> color x = B && digit x = Some 6) std_deck
|> List.hd
let blue7 =
List.filter (fun x -> color x = B && digit x = Some 7) std_deck
|> List.hd
let blue_draw2 =
List.filter
(fun x ->
color x = B
&& digit x = None
&& actions x
= {
skip = false;
reverse = false;
swap = (false, -1);
change_color = false;
}
&& draw_penalty x = 2)
std_deck
|> List.hd
let red_draw2 =
List.filter
(fun x ->
color x = R
&& digit x = None
&& actions x
= {
skip = false;
reverse = false;
swap = (false, -1);
change_color = false;
}
&& draw_penalty x = 2)
std_deck
|> List.hd
let draw4 =
List.filter (fun x -> draw_penalty x = 4) std_deck |> List.hd
let swap =
List.filter
(fun x ->
actions x
= {
skip = false;
reverse = false;
swap = (true, -1);
change_color = true;
})
std_deck
|> List.hd
(*** deck ***)
let no_17br_deck =
List.filter
(fun x ->
x = red1 || x = red2 || x = red3 || x = red4 || x = red5
|| x = red6 || x = red7 || x = blue1 || x = blue2 || x = blue3
|| x = blue4 || x = blue5 || x = blue6 || x = blue7)
std_deck
(*** players ***)
let p1 =
create_test "p1" [ red1; red2; red3; red4; red5; red6; red7 ] false 1
let p2 =
create_test "p2" [ red1; red2; red3; red4; red5; red6; red7 ] false 1
let p3 =
create_test "p3"
[ blue1; blue2; blue3; blue4; blue5; blue6; blue7 ]
false 3
let p4 =
create_test "p4"
[ blue1; blue2; blue3; blue4; blue5; blue6; blue7 ]
false 4
let p5 =
create_test "p5"
[ blue_draw2; blue2; blue3; blue4; blue5; blue6; blue7 ]
false 5
let p6 =
create_test "p6"
[ red_draw2; blue2; blue3; blue_draw2; blue5; blue6; blue7 ]
false 6
let p7 =
create_test "p7"
[ draw4; blue2; blue3; blue_draw2; blue5; blue6; blue7 ]
false 7
let p8 = create_test "p8" [ draw4 ] false 8
let p9 =
create_test "p9"
[ draw4; blue2; blue3; red_draw2; blue5; blue6; blue7 ]
false 9
let p10 = create_test "p10" [ swap; red5 ] false 10
(*** states ***)
let start_red0 = t_test no_17br_deck std_deck 0 red0 [ p1; p2; p3; p4 ]
let start_blue0 =
t_test no_17br_deck std_deck 0 blue0 [ p1; p2; p3; p4 ]
let start_blue0_2 =
t_test no_17br_deck std_deck 2 blue_draw2 [ p5; p2; p3; p4 ]
let start_blue0_2_p6 =
t_test no_17br_deck std_deck 2 blue_draw2 [ p6; p2; p3; p4 ]
let start_blue0_2_p7 =
t_test no_17br_deck std_deck 2 blue_draw2 [ p7; p2; p3; p4 ]
let nextp_uno = t_test no_17br_deck std_deck 0 blue6 [ p7; p8; p3; p4 ]
let nextp_uno_43 =
t_test no_17br_deck std_deck 0 blue6 [ p7; p8; p4; p3 ]
let nextp_uno4 = t_test no_17br_deck std_deck 0 blue6 [ p9; p8; p3; p4 ]
let nextp_uno_swap =
t_test no_17br_deck std_deck 0 blue6 [ p10; p8; p3; p4 ]
let both_std_deck =
t_test std_deck std_deck 2 blue_draw2 [ p6; p2; p3; p4 ]
let both_nobr_deck =
t_test no_17br_deck no_17br_deck 2 blue_draw2 [ p6; p2; p3; p4 ]
(**************************************************************)
let computer_suite =
[
action_test "no_17br red0 -> red1" start_red0 (Some red1);
action_test "no_17br blue0 -> None" start_blue0 None;
action_test "std blue0 2 -> blue_draw2" start_blue0_2
(Some blue_draw2);
action_test "std blue0 2 p6 -> red_draw2" start_blue0_2_p6
(Some red_draw2);
action_test "std blue0 2 p7 -> blue_draw2" start_blue0_2_p7
(Some blue_draw2);
action_test "nextp -> blue_draw2" nextp_uno (Some blue_draw2);
action_test "nextp_uno_43 -> blue_draw2" nextp_uno_43
(Some blue_draw2);
action_draw4_test "nextp_4 -> draw4" nextp_uno4;
action_swap_test "swap -> swap" nextp_uno_swap (Some swap);
action_test "std blue0 2 p6 -> red_draw2, both std" both_std_deck
(Some red_draw2);
action_test "std blue0 2 p6 -> red_draw2, both nobr" both_nobr_deck
(Some red_draw2);
]
let suite = "test suite for State" >::: computer_suite
(* let _ = run_test_tt_main suite *)