Apply rector, phpstan and php-cs-fixer
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-11-29 19:52:02 +01:00
parent f35c24d35d
commit b07b0b2ae8
22 changed files with 869 additions and 1105 deletions

View File

@ -2,56 +2,84 @@
namespace Tests;
use trizz\AdventOfCode\ExecuteDay;
use PHPUnit\Framework\TestCase;
use trizz\AdventOfCode\Solution;
class SolutionsTest extends TestCase
/**
* @internal
*/
final class SolutionsTest extends TestCase
{
/**
* @dataProvider loadSolutions
*/
public function testSolutionPart1Example(Solution $class): void
public function testSolutionPart1Example(Solution $solution): void
{
$this->runPart($class, part: 1, testExample: true);
$this->runPart($solution, part: 1, testExample: true);
}
/**
* @dataProvider loadSolutions
*
* @depends testSolutionPart1Example
*/
public function testSolutionPart1(Solution $class): void
public function testSolutionPart1(Solution $solution): void
{
$this->runPart($class, part: 1, testExample: false);
$this->runPart($solution, part: 1, testExample: false);
}
/**
* @dataProvider loadSolutions
*
* @depends testSolutionPart1
*/
public function testSolutionPart2Example(Solution $class): void
public function testSolutionPart2Example(Solution $solution): void
{
$this->runPart($class, part: 2, testExample: true);
$this->runPart($solution, part: 2, testExample: true);
}
/**
* @dataProvider loadSolutions
*
* @depends testSolutionPart2Example
*/
public function testSolutionPart2(Solution $class): void
public function testSolutionPart2(Solution $solution): void
{
$this->runPart($class, part: 2, testExample: false);
$this->runPart($solution, part: 2, testExample: false);
}
private function runPart(Solution $class, int $part, bool $testExample): void
/**
* @return array<string, array<int, Solution>>
*/
public function loadSolutions(): array
{
$classes = [];
for ($year = 15; $year <= date('y'); ++$year) {
if (is_dir(__DIR__.'/../src/Y'.$year)) {
for ($day = 1; $day < 26; ++$day) {
$className = sprintf('trizz\\AdventOfCode\\Y%d\\Day%d', $year, $day);
if (class_exists($className)) {
/** @var Solution $class */
$class = new $className();
$class->loadData();
$classes["Year '".$year.' / Day '.$day] = [$class];
}
}
}
}
return $classes;
}
private function runPart(Solution $solution, int $part, bool $testExample): void
{
if (
($testExample && $class->hasExampleData())
|| (!$testExample && $class->hasData())
($testExample && $solution->hasExampleData())
|| (!$testExample && $solution->hasData())
) {
$expectedResult = $class::${'part'.$part.($testExample ? 'Example' : null).'Result'};
$expectedResult = $solution::${'part'.$part.($testExample ? 'Example' : null).'Result'};
if ($expectedResult) {
$result = $class->{'part'.$part.'Data'}(useExampleData: $testExample);
$result = $solution->{'part'.$part.'Data'}(useExampleData: $testExample);
self::assertSame($expectedResult, $result);
} else {
$this->markTestSkipped('No '.($testExample ? 'example' : 'expected').' data for part '.$part.'.');
@ -60,23 +88,4 @@ class SolutionsTest extends TestCase
$this->markTestSkipped('No example and expected data for part '.$part.'.');
}
}
public function loadSolutions(): array
{
$classes = [];
for ($year = 15; $year <= date('y'); $year++) {
if (is_dir(__DIR__.'/../src/Y'.$year)) {
for ($day = 1; $day < 26; $day++) {
$className = sprintf("trizz\\AdventOfCode\\Y%d\\Day%d", $year, $day);
if (class_exists($className)) {
$class = new $className();
$class->loadData();
$classes['Year \''.$year.' / Day '.$day] = [$class];
}
}
}
}
return $classes;
}
}