xref: /web-php/tests/Unit/GenChallengeTest.php (revision 33dd2a89)
1<?php
2
3declare(strict_types=1);
4
5namespace phpweb\Test\Unit;
6
7use PHPUnit\Framework;
8
9#[Framework\Attributes\CoversFunction('gen_challenge')]
10#[Framework\Attributes\UsesFunction('gen_minus')]
11#[Framework\Attributes\UsesFunction('gen_plus')]
12#[Framework\Attributes\UsesFunction('print_infix')]
13#[Framework\Attributes\UsesFunction('print_prefix')]
14final class GenChallengeTest extends Framework\TestCase
15{
16    public static function setUpBeforeClass(): void
17    {
18        require_once __DIR__ . '/../../manual/spam_challenge.php';
19
20        mt_srand(9001);
21    }
22
23    public function testGenChallengeReturnsChallenge(): void {
24        $challenges = array_map(static function (): array {
25            [$function, $argumentOne, $argumentTwo, $question] = gen_challenge();
26
27            return [
28                'function' => $function,
29                'argumentOne' => $argumentOne,
30                'argumentTwo' => $argumentTwo,
31                'question' => $question,
32            ];
33        }, range(1, 20));
34
35        $expected = [
36            [
37                'function' => 'min',
38                'argumentOne' => 'two',
39                'argumentTwo' => 'one',
40                'question' => 'min(two, one)',
41            ],
42            [
43                'function' => 'minus',
44                'argumentOne' => 'five',
45                'argumentTwo' => 'five',
46                'question' => 'five minus five',
47            ],
48            [
49                'function' => 'minus',
50                'argumentOne' => 'four',
51                'argumentTwo' => 'four',
52                'question' => 'four minus four',
53            ],
54            [
55                'function' => 'min',
56                'argumentOne' => 'nine',
57                'argumentTwo' => 'seven',
58                'question' => 'min(nine, seven)',
59            ],
60            [
61                'function' => 'minus',
62                'argumentOne' => 'seven',
63                'argumentTwo' => 'six',
64                'question' => 'seven minus six',
65            ],
66            [
67                'function' => 'max',
68                'argumentOne' => 'three',
69                'argumentTwo' => 'six',
70                'question' => 'max(three, six)',
71            ],
72            [
73                'function' => 'max',
74                'argumentOne' => 'six',
75                'argumentTwo' => 'five',
76                'question' => 'max(six, five)',
77            ],
78            [
79                'function' => 'max',
80                'argumentOne' => 'four',
81                'argumentTwo' => 'three',
82                'question' => 'max(four, three)',
83            ],
84            [
85                'function' => 'min',
86                'argumentOne' => 'two',
87                'argumentTwo' => 'nine',
88                'question' => 'min(two, nine)',
89            ],
90            [
91                'function' => 'plus',
92                'argumentOne' => 'eight',
93                'argumentTwo' => 'one',
94                'question' => 'eight plus one',
95            ],
96            [
97                'function' => 'plus',
98                'argumentOne' => 'three',
99                'argumentTwo' => 'five',
100                'question' => 'three plus five',
101            ],
102            [
103                'function' => 'min',
104                'argumentOne' => 'eight',
105                'argumentTwo' => 'three',
106                'question' => 'min(eight, three)',
107            ],
108            [
109                'function' => 'max',
110                'argumentOne' => 'zero',
111                'argumentTwo' => 'nine',
112                'question' => 'max(zero, nine)',
113            ],
114            [
115                'function' => 'min',
116                'argumentOne' => 'five',
117                'argumentTwo' => 'nine',
118                'question' => 'min(five, nine)',
119            ],
120            [
121                'function' => 'minus',
122                'argumentOne' => 'six',
123                'argumentTwo' => 'four',
124                'question' => 'six minus four',
125            ],
126            [
127                'function' => 'max',
128                'argumentOne' => 'one',
129                'argumentTwo' => 'one',
130                'question' => 'max(one, one)',
131            ],
132            [
133                'function' => 'plus',
134                'argumentOne' => 'five',
135                'argumentTwo' => 'zero',
136                'question' => 'five plus zero',
137            ],
138            [
139                'function' => 'minus',
140                'argumentOne' => 'nine',
141                'argumentTwo' => 'eight',
142                'question' => 'nine minus eight',
143            ],
144            [
145                'function' => 'minus',
146                'argumentOne' => 'three',
147                'argumentTwo' => 'one',
148                'question' => 'three minus one',
149            ],
150            [
151                'function' => 'min',
152                'argumentOne' => 'three',
153                'argumentTwo' => 'one',
154                'question' => 'min(three, one)',
155            ],
156        ];
157
158        self::assertSame($expected, $challenges);
159    }
160}
161