-
Notifications
You must be signed in to change notification settings - Fork 634
Expand file tree
/
Copy pathTestAnswerTest.php
More file actions
102 lines (95 loc) · 2.98 KB
/
Copy pathTestAnswerTest.php
File metadata and controls
102 lines (95 loc) · 2.98 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
<?php
declare(strict_types=1);
namespace phpweb\Test\Unit;
use PHPUnit\Framework;
use phpweb\ProjectGlobals;
#[Framework\Attributes\CoversFunction('test_answer')]
#[Framework\Attributes\UsesFunction('minus')]
#[Framework\Attributes\UsesFunction('plus')]
final class TestAnswerTest extends Framework\TestCase
{
public static function setUpBeforeClass(): void
{
require_once ProjectGlobals::getPublicRoot() . '/manual/spam_challenge.php';
}
#[Framework\Attributes\DataProvider('provideFunctionArgumentsAnswerAndExpectedIsValid')]
public function testAnswerReturnsIsValid(
string $function,
string $argumentOne,
string $argumentTwo,
string $answer,
bool $expectedIsValid,
): void {
$isValid = test_answer(
$function,
$argumentOne,
$argumentTwo,
$answer,
);
self::assertSame($expectedIsValid, $isValid);
}
/**
* @return array<int, array{function: string, argumentOne: string, argumentTwo: string, answer: string, expectedIsValid: bool}>
*/
public static function provideFunctionArgumentsAnswerAndExpectedIsValid(): array
{
return [
[
'function' => 'max',
'argumentOne' => 'two',
'argumentTwo' => 'one',
'answer' => 'two',
'expectedIsValid' => true,
],
[
'function' => 'min',
'argumentOne' => 'two',
'argumentTwo' => 'one',
'answer' => 'one',
'expectedIsValid' => true,
],
[
'function' => 'minus',
'argumentOne' => 'five',
'argumentTwo' => 'five',
'answer' => 'zero',
'expectedIsValid' => true,
],
[
'function' => 'plus',
'argumentOne' => 'eight',
'argumentTwo' => 'one',
'answer' => 'nine',
'expectedIsValid' => true,
],
[
'function' => 'max',
'argumentOne' => 'three',
'argumentTwo' => 'six',
'answer' => 'nine',
'expectedIsValid' => false,
],
[
'function' => 'min',
'argumentOne' => 'two',
'argumentTwo' => 'nine',
'answer' => 'seven',
'expectedIsValid' => false,
],
[
'function' => 'minus',
'argumentOne' => 'seven',
'argumentTwo' => 'six',
'answer' => 'four',
'expectedIsValid' => false,
],
[
'function' => 'plus',
'argumentOne' => 'eight',
'argumentTwo' => 'one',
'answer' => 'seven',
'expectedIsValid' => false,
],
];
}
}