xref: /web-php/tests/Unit/TestAnswerTest.php (revision 33dd2a89)
1<?php
2
3declare(strict_types=1);
4
5namespace phpweb\Test\Unit;
6
7use PHPUnit\Framework;
8
9#[Framework\Attributes\CoversFunction('test_answer')]
10#[Framework\Attributes\UsesFunction('minus')]
11#[Framework\Attributes\UsesFunction('plus')]
12final class TestAnswerTest extends Framework\TestCase
13{
14    public static function setUpBeforeClass(): void
15    {
16        require_once __DIR__ . '/../../manual/spam_challenge.php';
17    }
18
19    #[Framework\Attributes\DataProvider('provideFunctionArgumentsAnswerAndExpectedIsValid')]
20    public function testAnswerReturnsIsValid(
21        string $function,
22        string $argumentOne,
23        string $argumentTwo,
24        string $answer,
25        bool $expectedIsValid,
26    ): void {
27        $isValid = test_answer(
28            $function,
29            $argumentOne,
30            $argumentTwo,
31            $answer,
32        );
33
34        self::assertSame($expectedIsValid, $isValid);
35    }
36
37    /**
38     * @return array<int, array{function: string, argumentOne: string, argumentTwo: string, answer: string, expectedIsValid: bool}>
39     */
40    public static function provideFunctionArgumentsAnswerAndExpectedIsValid(): array
41    {
42        return [
43            [
44                'function' => 'max',
45                'argumentOne' => 'two',
46                'argumentTwo' => 'one',
47                'answer' => 'two',
48                'expectedIsValid' => true,
49            ],
50            [
51                'function' => 'min',
52                'argumentOne' => 'two',
53                'argumentTwo' => 'one',
54                'answer' => 'one',
55                'expectedIsValid' => true,
56            ],
57            [
58                'function' => 'minus',
59                'argumentOne' => 'five',
60                'argumentTwo' => 'five',
61                'answer' => 'zero',
62                'expectedIsValid' => true,
63            ],
64            [
65                'function' => 'plus',
66                'argumentOne' => 'eight',
67                'argumentTwo' => 'one',
68                'answer' => 'nine',
69                'expectedIsValid' => true,
70            ],
71            [
72                'function' => 'max',
73                'argumentOne' => 'three',
74                'argumentTwo' => 'six',
75                'answer' => 'nine',
76                'expectedIsValid' => false,
77            ],
78            [
79                'function' => 'min',
80                'argumentOne' => 'two',
81                'argumentTwo' => 'nine',
82                'answer' => 'seven',
83                'expectedIsValid' => false,
84            ],
85            [
86                'function' => 'minus',
87                'argumentOne' => 'seven',
88                'argumentTwo' => 'six',
89                'answer' => 'four',
90                'expectedIsValid' => false,
91            ],
92            [
93                'function' => 'plus',
94                'argumentOne' => 'eight',
95                'argumentTwo' => 'one',
96                'answer' => 'seven',
97                'expectedIsValid' => false,
98            ],
99        ];
100    }
101}
102