62 lines
No EOL
1.9 KiB
PHP
62 lines
No EOL
1.9 KiB
PHP
<?php
|
|
|
|
namespace Lubiana\Aoc\Y2023\D04;
|
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* @covers \Lubiana\Aoc\Y2023\D04\Card
|
|
*/
|
|
class CardTest extends TestCase
|
|
{
|
|
/**
|
|
* Tests the 'fromString' method under normal conditions
|
|
* @covers \Lubiana\Aoc\Y2023\D04\Card::fromString
|
|
*/
|
|
public function testFromString(): void
|
|
{
|
|
$input = "Card 10: 12 22 1|13 14 15 1";
|
|
$expectedCard = new Card(
|
|
10,
|
|
[new Number(12), new Number(22), new Number(1)],
|
|
[new Number(13), new Number(14), new Number(15), new Number(1)]
|
|
);
|
|
|
|
$actualCard = Card::fromString($input);
|
|
|
|
$this->assertEquals($expectedCard, $actualCard);
|
|
}
|
|
|
|
#[DataProvider('cardGenerator')]
|
|
public function testGetPoints(string $input, int $expectedPoints): void
|
|
{
|
|
$this->assertEquals($expectedPoints, Card::fromString($input)->getPoints());
|
|
}
|
|
|
|
#[DataProvider('solveGenerator')]
|
|
public function testSolve(string $inputFile, int $solution, int $solutionSecond): void
|
|
{
|
|
$solver = new D04($inputFile);
|
|
$this->assertEquals($solution, $solver->solve());
|
|
$this->assertEquals($solutionSecond, $solver->solveSecond());
|
|
}
|
|
|
|
|
|
public static function solveGenerator(): \Generator
|
|
{
|
|
yield [D04::EXAMPLE_INPUT_FILE, 13, 30];
|
|
//yield [D04::INPUT_FILE, 26426, 6227972];
|
|
}
|
|
|
|
|
|
public static function cardGenerator(): \Generator
|
|
{
|
|
yield ['Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53', 8];
|
|
yield ['Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19', 2];
|
|
yield ['Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1', 2];
|
|
yield ['Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83', 1];
|
|
yield ['Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36', 0];
|
|
yield ['Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11', 0];
|
|
}
|
|
} |