-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ml
131 lines (114 loc) · 4.37 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
open OUnit2
open State
open Command
let maze = Maze.load "games/3110.csv"
let state = State.init_state maze
let pacman = Pacman.init 3 (Maze.center maze) UP
let state2 = State.next maze state (MOVE UP)
let state3 = State.next maze state2 (MOVE UP)
let state4 = State.next maze state3 (MOVE UP)
let state5 = State.next maze state4 (MOVE UP)
let invalid_maze_3ghosts = Maze.load "IllegalGames/3Ghosts.csv"
let invalid_maze_BlockedCorners = Maze.load "IllegalGames/BlockedCorners.csv"
let invalid_maze_NonRectangular= Maze.load "IllegalGames/NonRectangular.csv"
(** [make_pacman_test] constructs an OUnit test named [name] that asserts
the equality of [expected_output] with [State.pacman state].
*)
let make_pacman_test
(name: string)
(state: t)
(expected_output: Pacman.t) : test =
name >:: (fun _ -> assert_equal expected_output (State.pacman state))
(** [make_ghost_test] constructs an OUnit test named [name] that asserts
the equality of [expected_output] with [List.length (State.ghosts state)].
*)
let make_ghost_test
(name: string)
(state: t)
(expected_output: int) : test =
name >:: (fun _ -> assert_equal expected_output
(List.length (State.ghosts state)))
(** [make_score_test] constructs an OUnit test named [name] that asserts
the equality of [expected_output] with [State.score state].
*)
let make_score_test
(name: string)
(state: t)
(expected_output: int) : test =
name >:: (fun _ -> assert_equal expected_output (State.score state))
(** [make_dead_test] constructs an OUnit test named [name] that asserts
the equality of [expected_output] with [State.dead state].
*)
let make_dead_test
(name: string)
(state: t)
(expected_output:bool) : test =
name >:: (fun _-> assert_equal expected_output (State.dead state))
(** [make_beat_test] constructs an OUnit test named [name] that asserts
the equality of [expected_output] with [State.beat_level state].
*)
let make_beat_level_test
(name: string)
(state: t)
(expected_output:bool) : test =
name >:: (fun _-> assert_equal expected_output (State.beat_level state))
(** [make_respawn_test] constructs an OUnit test named [name] that asserts
the equality of [expected_output] with [State.respawn maze state].
*)
let make_respawn_test
(name: string)
(maze: Maze.t)
(state: t)
(expected_output:Pacman.t) : test =
name >:: (fun _-> assert_equal expected_output
(State.pacman (State.respawn maze state)))
(** [make_next_test] constructs an OUnit test named [name] that asserts
the equality of [expected_output] with [State.next maze state cmm].
*)
let make_next_test
(name: string)
(maze: Maze.t)
(state: t)
(cmm: Command.cmd)
(expected_output:Pacman.t) : test =
name >:: (fun _-> assert_equal expected_output
(State.pacman (State.next maze state cmm)))
let blocked_corner_maze =
let name = "" in
let blocked_corner_maze' =
try Some (Maze.rep_ok invalid_maze_BlockedCorners)
with Maze.MalformedFile "Corners need to be empty"-> None in
name >:: (fun _-> assert (blocked_corner_maze' == None))
let only_3ghost_maze =
let name = "" in
let only_3ghost_maze' =
try Some (Maze.rep_ok invalid_maze_3ghosts)
with Maze.MalformedFile "there needs to be exactly 4 ghosts"-> None in
name >:: (fun _-> assert (only_3ghost_maze' == None))
let state_tests =[
make_pacman_test "pac1" state pacman;
make_ghost_test "numghost1" state 4;
make_score_test "startscore1" state (-10);
make_score_test "nextscore1" state2 (0);
make_score_test "nextscore2" state3 (10);
make_score_test "nextscore3" state4 (20);
make_dead_test "dead1" state false;
make_beat_level_test "beatlevel1" state false;
make_respawn_test "respawn1" maze state (Pacman.init 2 (7,5) UP);
make_next_test "next1" maze state (MOVE UP) (Pacman.init 3 (7,4) UP);
make_next_test "next2" maze state2 (MOVE UP) (Pacman.init 3 (7,3) UP);
make_next_test "next3" maze state3 (MOVE UP) (Pacman.init 3 (7,2) UP);
make_next_test "next5" maze state (MOVE DOWN) (Pacman.init 3 (7,6) DOWN);
make_next_test "next6" maze state2 (MOVE DOWN) (Pacman.init 3 (7,5) DOWN);
make_next_test "next7" maze state3 (MOVE DOWN) (Pacman.init 3 (7,4) DOWN);
]
let maze_tests =[
blocked_corner_maze;
only_3ghost_maze
]
let suite =
"test suite for A7" >::: List.flatten [
state_tests;
maze_tests;
]
let _ = run_test_tt_main suite