Add test day command for easier testing while developing
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Tristan 2023-12-03 14:34:35 +01:00
parent 68f6ee867a
commit 929b87e513
Signed by: trizz
SSH Key Fingerprint: SHA256:Xsd2dTN+ZC3OZWfvuKIDMQ/1lWicuINSEPgRQw/CJT8
2 changed files with 58 additions and 0 deletions

2
aoc
View File

@ -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();

56
src/Commands/TestDay.php Normal file
View File

@ -0,0 +1,56 @@
<?php
namespace trizz\AdventOfCode\Commands;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
final class TestDay extends AbstractDayCommand
{
#[\Override]
protected function configure(): void
{
parent::configure();
$this
->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('<fg=bright-green>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('<fg=bright-green>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(' <fg=blue>%s:</>', $title));
$output->writeln(sprintf(' <fg=%s>Expected: </> <comment>%s</comment>', $color, $expected));
$output->writeln(sprintf(' <fg=%s>Result: </> <comment>%s</comment>', $color, $result));
}
}