Skip to content

Commit d8717d3

Browse files
authored
Add tests for gen_challenge() and test_answer()
Closes GH-632.
1 parent 352f784 commit d8717d3

File tree

2 files changed

+457
-0
lines changed

2 files changed

+457
-0
lines changed

tests/gen-challenge.phpt

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
--TEST--
2+
gen_challenge() generates a spam challenge
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/../manual/spam_challenge.php';
7+
8+
srand(9001);
9+
10+
$challenges = array_map(static function (): array {
11+
[$function, $argumentOne, $argumentTwo, $question] = gen_challenge();
12+
13+
return [
14+
'function' => $function,
15+
'argumentOne' => $argumentOne,
16+
'argumentTwo' => $argumentTwo,
17+
'question' => $question,
18+
];
19+
}, range(1, 20));
20+
21+
var_dump($challenges);
22+
23+
?>
24+
--EXPECT--
25+
array(20) {
26+
[0]=>
27+
array(4) {
28+
["function"]=>
29+
string(3) "min"
30+
["argumentOne"]=>
31+
string(3) "two"
32+
["argumentTwo"]=>
33+
string(3) "one"
34+
["question"]=>
35+
string(13) "min(two, one)"
36+
}
37+
[1]=>
38+
array(4) {
39+
["function"]=>
40+
string(5) "minus"
41+
["argumentOne"]=>
42+
string(4) "five"
43+
["argumentTwo"]=>
44+
string(4) "five"
45+
["question"]=>
46+
string(15) "five minus five"
47+
}
48+
[2]=>
49+
array(4) {
50+
["function"]=>
51+
string(5) "minus"
52+
["argumentOne"]=>
53+
string(4) "four"
54+
["argumentTwo"]=>
55+
string(4) "four"
56+
["question"]=>
57+
string(15) "four minus four"
58+
}
59+
[3]=>
60+
array(4) {
61+
["function"]=>
62+
string(3) "min"
63+
["argumentOne"]=>
64+
string(4) "nine"
65+
["argumentTwo"]=>
66+
string(5) "seven"
67+
["question"]=>
68+
string(16) "min(nine, seven)"
69+
}
70+
[4]=>
71+
array(4) {
72+
["function"]=>
73+
string(5) "minus"
74+
["argumentOne"]=>
75+
string(5) "seven"
76+
["argumentTwo"]=>
77+
string(3) "six"
78+
["question"]=>
79+
string(15) "seven minus six"
80+
}
81+
[5]=>
82+
array(4) {
83+
["function"]=>
84+
string(3) "max"
85+
["argumentOne"]=>
86+
string(5) "three"
87+
["argumentTwo"]=>
88+
string(3) "six"
89+
["question"]=>
90+
string(15) "max(three, six)"
91+
}
92+
[6]=>
93+
array(4) {
94+
["function"]=>
95+
string(3) "max"
96+
["argumentOne"]=>
97+
string(3) "six"
98+
["argumentTwo"]=>
99+
string(4) "five"
100+
["question"]=>
101+
string(14) "max(six, five)"
102+
}
103+
[7]=>
104+
array(4) {
105+
["function"]=>
106+
string(3) "max"
107+
["argumentOne"]=>
108+
string(4) "four"
109+
["argumentTwo"]=>
110+
string(5) "three"
111+
["question"]=>
112+
string(16) "max(four, three)"
113+
}
114+
[8]=>
115+
array(4) {
116+
["function"]=>
117+
string(3) "min"
118+
["argumentOne"]=>
119+
string(3) "two"
120+
["argumentTwo"]=>
121+
string(4) "nine"
122+
["question"]=>
123+
string(14) "min(two, nine)"
124+
}
125+
[9]=>
126+
array(4) {
127+
["function"]=>
128+
string(4) "plus"
129+
["argumentOne"]=>
130+
string(5) "eight"
131+
["argumentTwo"]=>
132+
string(3) "one"
133+
["question"]=>
134+
string(14) "eight plus one"
135+
}
136+
[10]=>
137+
array(4) {
138+
["function"]=>
139+
string(4) "plus"
140+
["argumentOne"]=>
141+
string(5) "three"
142+
["argumentTwo"]=>
143+
string(4) "five"
144+
["question"]=>
145+
string(15) "three plus five"
146+
}
147+
[11]=>
148+
array(4) {
149+
["function"]=>
150+
string(3) "min"
151+
["argumentOne"]=>
152+
string(5) "eight"
153+
["argumentTwo"]=>
154+
string(5) "three"
155+
["question"]=>
156+
string(17) "min(eight, three)"
157+
}
158+
[12]=>
159+
array(4) {
160+
["function"]=>
161+
string(3) "max"
162+
["argumentOne"]=>
163+
string(4) "zero"
164+
["argumentTwo"]=>
165+
string(4) "nine"
166+
["question"]=>
167+
string(15) "max(zero, nine)"
168+
}
169+
[13]=>
170+
array(4) {
171+
["function"]=>
172+
string(3) "min"
173+
["argumentOne"]=>
174+
string(4) "five"
175+
["argumentTwo"]=>
176+
string(4) "nine"
177+
["question"]=>
178+
string(15) "min(five, nine)"
179+
}
180+
[14]=>
181+
array(4) {
182+
["function"]=>
183+
string(5) "minus"
184+
["argumentOne"]=>
185+
string(3) "six"
186+
["argumentTwo"]=>
187+
string(4) "four"
188+
["question"]=>
189+
string(14) "six minus four"
190+
}
191+
[15]=>
192+
array(4) {
193+
["function"]=>
194+
string(3) "max"
195+
["argumentOne"]=>
196+
string(3) "one"
197+
["argumentTwo"]=>
198+
string(3) "one"
199+
["question"]=>
200+
string(13) "max(one, one)"
201+
}
202+
[16]=>
203+
array(4) {
204+
["function"]=>
205+
string(4) "plus"
206+
["argumentOne"]=>
207+
string(4) "five"
208+
["argumentTwo"]=>
209+
string(4) "zero"
210+
["question"]=>
211+
string(14) "five plus zero"
212+
}
213+
[17]=>
214+
array(4) {
215+
["function"]=>
216+
string(5) "minus"
217+
["argumentOne"]=>
218+
string(4) "nine"
219+
["argumentTwo"]=>
220+
string(5) "eight"
221+
["question"]=>
222+
string(16) "nine minus eight"
223+
}
224+
[18]=>
225+
array(4) {
226+
["function"]=>
227+
string(5) "minus"
228+
["argumentOne"]=>
229+
string(5) "three"
230+
["argumentTwo"]=>
231+
string(3) "one"
232+
["question"]=>
233+
string(15) "three minus one"
234+
}
235+
[19]=>
236+
array(4) {
237+
["function"]=>
238+
string(3) "min"
239+
["argumentOne"]=>
240+
string(5) "three"
241+
["argumentTwo"]=>
242+
string(3) "one"
243+
["question"]=>
244+
string(15) "min(three, one)"
245+
}
246+
}

0 commit comments

Comments
 (0)