54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Lubiana\Aoc\Y2023\D03;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class GridTest extends TestCase
|
|
{
|
|
public function testSmall(): void
|
|
{
|
|
$grid = Grid::fromFile(D03::SMALL_FILE);
|
|
$numbers = array_map(fn (Number $n) => $n->value, $grid->getNumbers());
|
|
$this->assertEquals([939, 644, 791, 551, 35, 937, 806, 536, 930, 703, 565, 640], $numbers);
|
|
}
|
|
|
|
public function testValid(): void
|
|
{
|
|
$grid = Grid::fromFile(D03::SMALL_FILE);
|
|
$valids = $grid->getValidNumbers();
|
|
$numbers = array_map(fn (Number $n) => $n->value, $valids);
|
|
$this->assertEquals([640], $numbers);
|
|
}
|
|
|
|
public function testSymbols(): void
|
|
{
|
|
$grid = Grid::fromFile(D03::SMALL_FILE);
|
|
$valids = $grid->getSymbols();
|
|
$numbers = array_map(fn (Coordinate $n) => $n->char, $valids);
|
|
$this->assertEquals(['*', '&', '*', '*'], $numbers);
|
|
}
|
|
|
|
public function testExampleInput(): void
|
|
{
|
|
$solver = new D03(D03::TESTFILE);
|
|
$this->assertEquals(4361, $solver->solve());
|
|
}
|
|
|
|
public function testExampleRatio(): void
|
|
{
|
|
$solver = new D03(D03::TESTFILE);
|
|
$this->assertEquals(467835, $solver->solveRatio());
|
|
}
|
|
public function testFullInput(): void
|
|
{
|
|
$solver = new D03;
|
|
$this->assertEquals(543867, $solver->solve());
|
|
}
|
|
|
|
public function testFullRatio(): void
|
|
{
|
|
$solver = new D03;
|
|
$this->assertEquals(79613331, $solver->solveRatio());
|
|
}
|
|
}
|