diff --git a/aoc b/aoc index 25c0ea8..7be3c49 100755 --- a/aoc +++ b/aoc @@ -6,6 +6,7 @@ use NunoMaduro\Collision\Provider as CollisionProvider; use Symfony\Component\Console\Application; use trizz\AdventOfCode\Commands\ExecuteDay; use trizz\AdventOfCode\Commands\Puzzle; +use trizz\AdventOfCode\Commands\TestDay; (new CollisionProvider())->register(); @@ -13,6 +14,7 @@ $application = new Application('Advent of Code by trizz'); $application->add(new Puzzle()); $application->add(new ExecuteDay()); +$application->add(new TestDay()); try { $application->run(); diff --git a/src/Commands/TestDay.php b/src/Commands/TestDay.php new file mode 100644 index 0000000..0a34c37 --- /dev/null +++ b/src/Commands/TestDay.php @@ -0,0 +1,56 @@ +setName('test') + ->setDescription('Test day'); + } + + #[\Override] + protected function execute(InputInterface $input, OutputInterface $output): int + { + $results = $this->getSolutions(); + $solution = $this->loadClass(); + + if (in_array($this->part, [0, 1], true)) { + $output->writeln('Part 1'); + $this->render($output, 'Example', $solution::$part1ExampleResult, $results['part1Example']); + $this->render($output, 'Puzzle', $solution::$part1Result, $results['part1']); + } + + if ($this->part === 0) { + $output->writeln(str_repeat('-', strlen($this->title))); + } + + if (in_array($this->part, [0, 2], true)) { + $output->writeln('Part 2'); + $this->render($output, 'Example', $solution::$part2ExampleResult, $results['part2Example']); + $this->render($output, 'Puzzle', $solution::$part2Result, $results['part2']); + } + + return Command::SUCCESS; + } + + private function render(OutputInterface $output, string $title, null|int|string $expected, null|int|string $result): void + { + if ($title === 'Example' && $this->skipExamples) { + return; + } + + $color = $expected === $result ? 'green' : 'red'; + $output->writeln(sprintf(' %s:', $title)); + $output->writeln(sprintf(' Expected: %s', $color, $expected)); + $output->writeln(sprintf(' Result: %s', $color, $result)); + } +}