aoc/tests/Lubiana/Aoc/Y2023/D02/GameTest.php
2023-12-10 12:49:11 +01:00

43 lines
No EOL
1.7 KiB
PHP

<?php
use Lubiana\Aoc\Y2023\D02\Set;
use PHPUnit\Framework\TestCase;
class GameTest extends TestCase
{
public static function gameProvider(): \Generator
{
yield 'Game1' => ['Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green', 1, true, 48];
yield 'Game2' => ["Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue", 2, true, 12];
yield 'Game3' => ["Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red", 3, false, 1560];
yield 'Game4' => ["Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red", 4, false, 630];
yield 'Game5' => ["Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green", 5, true, 36];
}
#[\PHPUnit\Framework\Attributes\DataProvider('gameProvider')]
public function testGameCreation(string $input, int $expectedId): void
{
$this->assertEquals($expectedId, \Lubiana\Aoc\Y2023\D02\Game::fromString($input)->id);
}
#[\PHPUnit\Framework\Attributes\DataProvider('gameProvider')]
public function testPower(string $input, int $expectedId, bool $isValid, int $power): void
{
$this->assertEquals(
$power,
\Lubiana\Aoc\Y2023\D02\Game::fromString($input)->withPower()->power
);
}
#[\PHPUnit\Framework\Attributes\DataProvider('gameProvider')]
public function testIsValid(string $input, int $expectedId, bool $isValid): void
{
$configurationSet = [
new Set(12, 'red'),
new Set(13, 'green'),
new Set(14, 'blue'),
];
$game = \Lubiana\Aoc\Y2023\D02\Game::fromString($input);
$this->assertEquals($isValid, $game->isValid($configurationSet));
}
}