1
0
mirror of https://github.com/php/web-php.git synced 2026-03-24 15:22:19 +01:00
Files
archived-web-php/tests/Unit/TestAnswerTest.php
2024-02-13 16:16:24 +03:00

102 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
namespace phpweb\Test\Unit;
use PHPUnit\Framework;
#[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 __DIR__ . '/../../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,
],
];
}
}