-
Notifications
You must be signed in to change notification settings - Fork 634
Expand file tree
/
Copy pathGenChallengeTest.php
More file actions
161 lines (152 loc) · 4.97 KB
/
Copy pathGenChallengeTest.php
File metadata and controls
161 lines (152 loc) · 4.97 KB
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
<?php
declare(strict_types=1);
namespace phpweb\Test\Unit;
use PHPUnit\Framework;
use phpweb\ProjectGlobals;
#[Framework\Attributes\CoversFunction('gen_challenge')]
#[Framework\Attributes\UsesFunction('gen_minus')]
#[Framework\Attributes\UsesFunction('gen_plus')]
#[Framework\Attributes\UsesFunction('print_infix')]
#[Framework\Attributes\UsesFunction('print_prefix')]
final class GenChallengeTest extends Framework\TestCase
{
public static function setUpBeforeClass(): void
{
require_once ProjectGlobals::getPublicRoot() . '/manual/spam_challenge.php';
mt_srand(9001);
}
public function testGenChallengeReturnsChallenge(): void {
$challenges = array_map(static function (): array {
[$function, $argumentOne, $argumentTwo, $question] = gen_challenge();
return [
'function' => $function,
'argumentOne' => $argumentOne,
'argumentTwo' => $argumentTwo,
'question' => $question,
];
}, range(1, 20));
$expected = [
[
'function' => 'min',
'argumentOne' => 'two',
'argumentTwo' => 'one',
'question' => 'min(two, one)',
],
[
'function' => 'minus',
'argumentOne' => 'five',
'argumentTwo' => 'five',
'question' => 'five minus five',
],
[
'function' => 'minus',
'argumentOne' => 'four',
'argumentTwo' => 'four',
'question' => 'four minus four',
],
[
'function' => 'min',
'argumentOne' => 'nine',
'argumentTwo' => 'seven',
'question' => 'min(nine, seven)',
],
[
'function' => 'minus',
'argumentOne' => 'seven',
'argumentTwo' => 'six',
'question' => 'seven minus six',
],
[
'function' => 'max',
'argumentOne' => 'three',
'argumentTwo' => 'six',
'question' => 'max(three, six)',
],
[
'function' => 'max',
'argumentOne' => 'six',
'argumentTwo' => 'five',
'question' => 'max(six, five)',
],
[
'function' => 'max',
'argumentOne' => 'four',
'argumentTwo' => 'three',
'question' => 'max(four, three)',
],
[
'function' => 'min',
'argumentOne' => 'two',
'argumentTwo' => 'nine',
'question' => 'min(two, nine)',
],
[
'function' => 'plus',
'argumentOne' => 'eight',
'argumentTwo' => 'one',
'question' => 'eight plus one',
],
[
'function' => 'plus',
'argumentOne' => 'three',
'argumentTwo' => 'five',
'question' => 'three plus five',
],
[
'function' => 'min',
'argumentOne' => 'eight',
'argumentTwo' => 'three',
'question' => 'min(eight, three)',
],
[
'function' => 'max',
'argumentOne' => 'zero',
'argumentTwo' => 'nine',
'question' => 'max(zero, nine)',
],
[
'function' => 'min',
'argumentOne' => 'five',
'argumentTwo' => 'nine',
'question' => 'min(five, nine)',
],
[
'function' => 'minus',
'argumentOne' => 'six',
'argumentTwo' => 'four',
'question' => 'six minus four',
],
[
'function' => 'max',
'argumentOne' => 'one',
'argumentTwo' => 'one',
'question' => 'max(one, one)',
],
[
'function' => 'plus',
'argumentOne' => 'five',
'argumentTwo' => 'zero',
'question' => 'five plus zero',
],
[
'function' => 'minus',
'argumentOne' => 'nine',
'argumentTwo' => 'eight',
'question' => 'nine minus eight',
],
[
'function' => 'minus',
'argumentOne' => 'three',
'argumentTwo' => 'one',
'question' => 'three minus one',
],
[
'function' => 'min',
'argumentOne' => 'three',
'argumentTwo' => 'one',
'question' => 'min(three, one)',
],
];
self::assertSame($expected, $challenges);
}
}