-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ml
115 lines (110 loc) · 3.83 KB
/
test.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
open OUnit2
open Gameplay
open Gamelogic
open Types
let board = [|[|Some 8; Some 4; Some 4; Some 4|];
[|None; Some 4; Some 4; Some 4|];
[|Some 4; Some 2; None; None|];
[|Some 4; Some 4; None; Some 2|]|]
let score = ref 0
let gameplay_tests = [
"Check is_empty_square True" >:: (fun _ -> assert_equal
true
(is_empty_square (None)));
"Check is_empty_square False" >:: (fun _ -> assert_equal
false
(is_empty_square (Some 8)));
"Check init" >:: (fun _ -> assert_equal
{
evil = ref false;
s = ref 0;
b = [|[|None; None; None; None|];
[|None; None; None; None|];
[|None; None; None; None|];
[|None; None; None; Some 2|]|]
}
(init_board ()));
"Check if 2048 square is 2048 square" >:: (fun _ -> assert_equal
true
(check_2048_square (Some 2048)));
"Check if non 2048 square is 2048 square" >:: (fun _ -> assert_equal
false
(check_2048_square (Some 4)));
"Check winning board" >:: (fun _ -> assert_equal
true
(check_winning_board [|[|None; None; None; None|];
[|None; None; None; None|];
[|None; None; None; None|];
[|None; None; None; Some 2048|]|]));
"Check non winning board" >:: (fun _ -> assert_equal
false
(check_winning_board [|[|None; None; None; None|];
[|None; None; None; None|];
[|None; None; None; Some 1048|];
[|None; None; None; Some 1048|]|]));
"Check empty squares" >:: (fun _ -> assert_equal
[(0, 1); (0, 2); (1, 1); (1, 2); (1, 3); (2, 0); (2, 3); (3, 0); (3, 1)]
(empty_squares [|[|Some 4; None; None; Some 4|];
[|Some 2; None; None; None|];
[|None; Some 2; Some 4; None|];
[|None; None; Some 2; Some 2|]|]));
"Check empty squares" >:: (fun _ -> assert_equal
[]
(empty_squares [|[|Some 4; Some 4; Some 4; Some 4|];
[|Some 2; Some 4; Some 4; Some 4|];
[|Some 4; Some 2; Some 4; Some 4|];
[|Some 4; Some 4; Some 2; Some 2|]|]));
"Find max square" >:: (fun _ -> assert_equal
(3,2)
(find_max_sq [|[|Some 4; Some 4; Some 4; Some 4|];
[|Some 2; Some 4; Some 4; Some 4|];
[|Some 4; Some 2; Some 4; Some 4|];
[|Some 4; Some 4; Some 8; Some 2|]|]));
"Find max square" >:: (fun _ -> assert_equal
(0,0)
(find_max_sq [|[|Some 4; Some 4; Some 4; Some 4|];
[|Some 2; Some 4; Some 4; Some 4|];
[|Some 4; Some 2; Some 4; Some 4|];
[|Some 4; Some 4; Some 2; Some 2|]|]));
]
(* Shift testing was tested through gameplay as shifting
* functions returned units and could not predict random
* square placement. Score is used as a correctness
* indicator. *)
let gamelogic_tests = [
"Check square_value 0" >:: (fun _ -> assert_equal
0
(square_value (None)));
"Check square_value 2" >:: (fun _ -> assert_equal
2
(square_value (Some 2)));
(* These tests have been commented as they raise warnings for
* re-initializing score and board to their initial state.
* This is done to avoid unintended behavior. Feel free to uncomment;
* all tests will pass. *)
(* "Move Right" >:: (fun _ -> assert_equal
24
(score = ref 0;
board = [|[|Some 8; Some 4; Some 4; Some 4|];
[|None; Some 4; Some 4; Some 4|];
[|Some 4; Some 2; None; None|];
[|Some 4; Some 4; None; Some 2|]|];
move Right board score; !score));
"Move Down" >:: (fun _ -> assert_equal
32
(score = ref 0;
board = [|[|Some 8; Some 4; Some 4; Some 4|];
[|None; Some 4; Some 4; Some 4|];
[|Some 4; Some 2; None; None|];
[|Some 4; Some 4; None; Some 2|]|];
move Down board score; !score));
"Move Left" >:: (fun _ -> assert_equal
24
(score = ref 0;
board = [|[|Some 8; Some 4; Some 4; Some 4|];
[|None; Some 4; Some 4; Some 4|];
[|Some 4; Some 2; None; None|];
[|Some 4; Some 4; None; Some 2|]|];
move Left board score; !score)); *)
]
let _ = run_test_tt_main ("suite" >::: gameplay_tests @ gamelogic_tests)