forked from miage-lille/tennis-kata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_test.ml
177 lines (143 loc) · 5.07 KB
/
game_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
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
open Tennis.Game
(* We define Alcotest.TESTABLE for Tennis.Game types *)
let player =
Alcotest.testable (Fmt.using Tennis.Game.string_of_player Fmt.string) ( = )
let score =
Alcotest.testable (Fmt.using Tennis.Game.string_of_score Fmt.string) ( = )
(* We define our test case below *)
(* TESTS for tooling functions *)
let given_Player_one_when_string_of_player () =
Alcotest.(check string)
"Player_one is Player 1"
"Player 1"
(string_of_player Player_one)
let given_Player_one_when_other_player () =
Alcotest.(check player)
"other_player is Player_two"
Player_two
(other_player Player_one)
let given_Player_one_when_string_of_player () =
Alcotest.(check string)
"Player_one is Player 1"
"Player 1"
(string_of_player Player_one)
(* TEST SET for tooling functions *)
let tooling_set =
let open Alcotest in
[ test_case
(* text display in the console for the test *)
"Given Player_one then string_of_player is Player 1"
(* always use `Quick mode *)
`Quick
(* the test define above *)
given_Player_one_when_string_of_player
; test_case
"Given Player_one then other player is Player_two"
`Quick
given_Player_one_when_other_player
]
(* TESTS for transition functions *)
let given_deuce_when_player_one_wins () =
Alcotest.(check score)
"score is Advantage Player_one"
(* to change when we will know how represent Advantage *)
(raise @@ Failure "How represent Advantage Value")
(score_when_deuce Player_one)
let given_deuce_when_player_two_wins () =
Alcotest.(check score)
"score is Advantage Player_two"
(raise @@ Failure "How represent Advantage Value")
(score_when_deuce Player_two)
let given_advantage_when_advantaged_player_wins () =
let advantaged_player = Player_one in
let winner = advantaged_player in
Alcotest.(check score)
"score is Game advantaged_player"
(Game advantaged_player)
(score_when_advantage advantaged_player winner)
let given_advantage_when_other_player_wins () =
let advantaged_player = Player_one in
let winner = other_player advantaged_player in
Alcotest.(check score)
"score is Deuce"
Deuce
(score_when_advantage advantaged_player winner)
let given_player_one_at_40_when_player_one_wins () =
Alcotest.(check score)
"score is Game for Player_one"
(Game Player_one)
(raise @@ Failure "How to code score_when_forty")
let given_player_one_at_40_other_at_30_when_other_wins () =
Alcotest.(check score)
"score is Deuce"
Deuce
(raise @@ Failure "How to code score_when_forty")
let given_player_one_at_40_other_at_15_when_other_wins () =
Alcotest.(check score)
"score is 40 / 30"
Deuce
(raise @@ Failure "How to code score_when_forty")
let given_player_one_at_15_other_at_15_when_player_one_wins () =
Alcotest.(check score)
"score is 30 / 15"
(raise @@ Failure "You turn to code the expected result")
(raise @@ Failure "You turn to code the test")
let given_player_one_at_0_other_at_15_when_other_wins () =
Alcotest.(check score)
"score is 0 / 30"
(raise @@ Failure "You turn to code the expected result")
(raise @@ Failure "You turn to code the test")
let given_player_one_at_30_other_at_15_when_player_one_wins () =
Alcotest.(check score)
"score is 40 / 15"
(raise @@ Failure "You turn to code the expected result")
(raise @@ Failure "You turn to code the test")
(* TEST SET for transition functions *)
let transitions_set =
let open Alcotest in
[ test_case
"Given Deuce when Player_one wins then score is Advantage Player_one"
`Quick
given_deuce_when_player_one_wins
; test_case
"Given Deuce when Player_two wins then score is Advantage Player_two"
`Quick
given_deuce_when_player_two_wins
; test_case
"Given Advantage when advantaged player wins then score is Game \
advantaged_player"
`Quick
given_advantage_when_advantaged_player_wins
; test_case
"Given Advantage when other player wins then score is Deuce"
`Quick
given_advantage_when_other_player_wins
; test_case
"Given Player_one at 40 when Player_one wins then score is Game \
Player_one"
`Quick
given_player_one_at_40_when_player_one_wins
; test_case
"Given Player_one at 40 | other at 30 when other wins then score is Deuce"
`Quick
given_player_one_at_40_other_at_30_when_other_wins
; test_case
"Given Player_one at 40 | other at 0 when other wins then score is 40 / \
30"
`Quick
given_player_one_at_40_other_at_15_when_other_wins
; test_case
"Given Player_one at 15 | other at 15 when other wins then score is 30 / \
15"
`Quick
given_player_one_at_15_other_at_15_when_player_one_wins
; test_case
"Given Player_one at 0 | other at 15 when other wins then score is 0 / 30"
`Quick
given_player_one_at_0_other_at_15_when_other_wins
; test_case
"Given Player_one at 30 | other at 15 when other wins then score is 40 / \
15"
`Quick
given_player_one_at_30_other_at_15_when_player_one_wins
]