From f5968c4f271e8ff97664fa8b3a5d0e4e0fe295b7 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 2 Jan 2025 14:21:38 +0100 Subject: [PATCH] refact: rewrite of the library - Remove Generators - It was not necessary to keep them - Switch to PHPUnit 11 - Remove temporarily drupol/php-conventions, deps issue with vimeo/psalm - Remove methods toArray and count - Remove custom interfaces - Update CI --- .editorconfig | 1 - .envrc | 1 + .github/workflows/continuous-integration.yml | 20 +- composer.json | 26 +- phpunit.xml | 26 + src/Combinatorics.php | 78 +- src/GeneratorInterface.php | 25 - src/Generators/Combinations.php | 60 -- src/Generators/Fibonacci.php | 39 - src/Generators/FiniteGroup.php | 38 - src/Generators/NGrams.php | 43 - src/Generators/Perfect.php | 23 - src/Generators/Permutations.php | 98 -- src/Generators/Prime.php | 23 - src/Generators/PrimeFactors.php | 30 - src/Generators/Product.php | 45 - src/Generators/Shift.php | 31 - src/IteratorInterface.php | 16 - src/Iterators.php | 25 +- src/Iterators/Combinations.php | 68 +- src/Iterators/Cycle.php | 2 +- src/Iterators/Fibonacci.php | 48 +- src/Iterators/FiniteGroup.php | 4 +- src/Iterators/NGrams.php | 59 +- src/Iterators/Perfect.php | 2 +- src/Iterators/Prime.php | 2 +- src/Iterators/PrimeFactors.php | 2 +- src/Iterators/Product.php | 2 +- src/Iterators/Rotation.php | 2 +- src/Iterators/Shift.php | 2 +- tests/fixtures/combinations.yml | 103 +-- tests/fixtures/cycle.yml | 15 +- tests/fixtures/fibonacci.yml | 8 +- tests/fixtures/finitegroup.yml | 5 +- tests/fixtures/ngrams.yml | 20 +- tests/fixtures/perfect.yml | 18 +- tests/fixtures/permutations.yml | 850 ++++++++++++++---- tests/fixtures/prime.yml | 182 +++- tests/fixtures/primefactors.yml | 15 +- tests/fixtures/product.yml | 104 ++- tests/fixtures/rotation.yml | 25 +- tests/fixtures/shift.yml | 20 +- tests/phpunit.xml | 20 - .../{AbstractTest.php => AbstractTester.php} | 12 +- tests/src/Generators/CombinationsTest.php | 47 - tests/src/Generators/FibonacciTest.php | 46 - tests/src/Generators/FiniteGroupTest.php | 46 - tests/src/Generators/PerfectTest.php | 53 -- tests/src/Generators/PermutationsTest.php | 48 - tests/src/Generators/PrimeFactorsTest.php | 46 - tests/src/Generators/PrimeTest.php | 54 -- tests/src/Generators/ProductTest.php | 46 - tests/src/Generators/ShiftTest.php | 38 - tests/src/Iterators/CombinationsTest.php | 42 +- tests/src/Iterators/CycleTest.php | 25 +- tests/src/Iterators/FibonacciTest.php | 35 +- tests/src/Iterators/FiniteGroupTest.php | 34 +- tests/src/Iterators/NgramsTest.php | 30 +- tests/src/Iterators/PerfectTest.php | 34 +- tests/src/Iterators/PrimeFactorsTest.php | 34 +- tests/src/Iterators/PrimeTest.php | 34 +- tests/src/Iterators/ProductTest.php | 34 +- tests/src/Iterators/RotationTest.php | 26 +- tests/src/Iterators/ShiftTest.php | 25 +- 64 files changed, 1197 insertions(+), 1818 deletions(-) create mode 100644 .envrc create mode 100644 phpunit.xml delete mode 100644 src/GeneratorInterface.php delete mode 100644 src/Generators/Combinations.php delete mode 100644 src/Generators/Fibonacci.php delete mode 100644 src/Generators/FiniteGroup.php delete mode 100644 src/Generators/NGrams.php delete mode 100644 src/Generators/Perfect.php delete mode 100644 src/Generators/Permutations.php delete mode 100644 src/Generators/Prime.php delete mode 100644 src/Generators/PrimeFactors.php delete mode 100644 src/Generators/Product.php delete mode 100644 src/Generators/Shift.php delete mode 100644 src/IteratorInterface.php delete mode 100644 tests/phpunit.xml rename tests/src/{AbstractTest.php => AbstractTester.php} (79%) delete mode 100644 tests/src/Generators/CombinationsTest.php delete mode 100644 tests/src/Generators/FibonacciTest.php delete mode 100644 tests/src/Generators/FiniteGroupTest.php delete mode 100644 tests/src/Generators/PerfectTest.php delete mode 100644 tests/src/Generators/PermutationsTest.php delete mode 100644 tests/src/Generators/PrimeFactorsTest.php delete mode 100644 tests/src/Generators/PrimeTest.php delete mode 100644 tests/src/Generators/ProductTest.php delete mode 100644 tests/src/Generators/ShiftTest.php diff --git a/.editorconfig b/.editorconfig index 173228f..47c1c7b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,4 +6,3 @@ charset = utf-8 max_line_length = 80 indent_style = space indent_size = 4 -insert_final_newline = true diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..46f4e96 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake github:loophp/nix-shell#env-php82 --impure diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index ddc1b5d..afb86ab 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest, windows-latest, macOS-latest] - php-versions: ['7.1', '7.2', '7.3', '7.4'] + php-versions: ["8.2", "8.3"] steps: - name: Checkout @@ -26,7 +26,7 @@ jobs: uses: shivammathur/setup-php@master with: php-version: ${{ matrix.php-versions }} - extensions: mbstring,xdebug + extensions: mbstring,pcov - name: Get Composer Cache Directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" @@ -41,17 +41,5 @@ jobs: - name: Install dependencies run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader - - name: Run Grumphp - run: vendor/bin/grumphp run --no-ansi -n - env: - STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} - - - name: Send PSALM data - run: vendor/bin/psalm --shepherd --stats - continue-on-error: true - - - name: Scrutinizer - run: | - wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml - continue-on-error: true + - name: Run Tests + run: composer phpunit diff --git a/composer.json b/composer.json index 86870c8..ed11f17 100644 --- a/composer.json +++ b/composer.json @@ -21,25 +21,35 @@ } ], "require": { - "php": ">= 7.1.3" + "php": ">= 8.2" }, "require-dev": { - "drupol/php-conventions": "^1.7.1", - "phpunit/php-code-coverage": "^4 || ^5", - "phpunit/phpunit": "^6 || ^7" + "ext-pcov": "*", + "phpunit/php-code-coverage": "^11", + "phpunit/phpunit": "^11", + "symfony/finder": "^7.2", + "symfony/yaml": "^7.2" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "ergebnis/composer-normalize": true, + "phpro/grumphp": true, + "phpstan/extension-installer": true + } }, "autoload": { "psr-4": { - "drupol\\phpermutations\\": "src/", + "drupol\\phpermutations\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { "drupol\\phpermutations\\Tests\\": "tests/src/" } }, "scripts": { - "grumphp": "./vendor/bin/grumphp run", - "phpunit": "./vendor/bin/phpunit --coverage-clover build/logs/clover.xml -c tests/phpunit.xml tests" + "phpunit": "./vendor/bin/phpunit --coverage-clover build/logs/clover.xml -c phpunit.xml tests" }, "support": { "issues": "https://github.com/drupol/phpermutations/issues", diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..a825b0e --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,26 @@ + + + + + tests + + + + + + src + + + diff --git a/src/Combinatorics.php b/src/Combinatorics.php index dafe832..86f741c 100644 --- a/src/Combinatorics.php +++ b/src/Combinatorics.php @@ -8,83 +8,29 @@ abstract class Combinatorics { - /** - * The dataset. - * - * @var array - */ protected $dataset; - /** - * The number of values in the dataset. - * - * @var int - */ - protected $datasetCount; + protected int $datasetCount; - /** - * The length. - * - * @var int - */ protected $length; - /** - * Combinatorics constructor. - * - * @param array $dataset - * The dataset - * @param int|null $length - * The length - */ - public function __construct(array $dataset = [], $length = null) + public function __construct(array $dataset = [], ?int $length = null) { $this->setDataset($dataset); $this->datasetCount = count($this->dataset); $this->setLength($length); } - /** - * Count elements of an object. - * - * @return int - * The number of element - */ - public function count(): int - { - return count($this->toArray()); - } - - /** - * Get the dataset. - * - * @return mixed[] - * The dataset - */ public function getDataset(): array { return $this->dataset; } - /** - * Get the length. - * - * @return int - * The length - */ public function getLength(): int { return (int) $this->length; } - /** - * Set the dataset. - * - * @param array $dataset - * The dataset - * - * @return $this - */ public function setDataset(array $dataset = []): Combinatorics { $this->dataset = $dataset; @@ -92,15 +38,7 @@ public function setDataset(array $dataset = []): Combinatorics return $this; } - /** - * Set the length. - * - * @param int|null $length - * The length - * - * @return $this - */ - public function setLength($length = null): Combinatorics + public function setLength(?int $length = null): Combinatorics { $length = $length ?? $this->datasetCount; $this->length = (abs($length) > $this->datasetCount) ? $this->datasetCount : $length; @@ -108,14 +46,6 @@ public function setLength($length = null): Combinatorics return $this; } - /** - * @return array - */ - public function toArray(): array - { - return []; - } - /** * Compute the factorial of an integer. * @@ -127,7 +57,7 @@ public function toArray(): array * @return int * The factorial of $n */ - protected function fact($n, $total = 1): int + protected function fact(int $n, int $total = 1): int { return (2 > $n) ? $total : $this->fact($n - 1, $total * $n); } diff --git a/src/GeneratorInterface.php b/src/GeneratorInterface.php deleted file mode 100644 index 7a4fee8..0000000 --- a/src/GeneratorInterface.php +++ /dev/null @@ -1,25 +0,0 @@ - - * The generator - */ - public function generator(): Generator; - - /** - * Convert the generator into an array. - * - * @return array - */ - public function toArray(): array; -} diff --git a/src/Generators/Combinations.php b/src/Generators/Combinations.php deleted file mode 100644 index d9af7d4..0000000 --- a/src/Generators/Combinations.php +++ /dev/null @@ -1,60 +0,0 @@ - - */ -class Combinations extends CombinationsIterator implements GeneratorInterface -{ - /** - * {@inheritdoc} - */ - public function generator(): Generator - { - return $this->get($this->getDataset(), $this->getLength()); - } - - /** - * The generator. - * - * @param array $dataset - * The dataset - * @param int $length - * The length - * - * @return Generator - */ - protected function get(array $dataset, $length): Generator - { - $originalLength = count($dataset); - $remainingLength = $originalLength - $length + 1; - - for ($i = 0; $i < $remainingLength; ++$i) { - $current = $dataset[$i]; - - if (1 === $length) { - yield [$current]; - } else { - $remaining = array_slice($dataset, $i + 1); - - foreach ($this->get($remaining, $length - 1) as $permutation) { - array_unshift($permutation, $current); - - yield $permutation; - } - } - } - } -} diff --git a/src/Generators/Fibonacci.php b/src/Generators/Fibonacci.php deleted file mode 100644 index a3afb86..0000000 --- a/src/Generators/Fibonacci.php +++ /dev/null @@ -1,39 +0,0 @@ -get(); - } - - /** - * The generator. - * - * @return Generator - */ - protected function get(): Generator - { - $a = 0; - $b = 1; - $to = $this->getMaxLimit(); - - while (0 < $to) { - yield $a; - - [$a, $b] = [$b, $a + $b]; - --$to; - } - } -} diff --git a/src/Generators/FiniteGroup.php b/src/Generators/FiniteGroup.php deleted file mode 100644 index b6caa7c..0000000 --- a/src/Generators/FiniteGroup.php +++ /dev/null @@ -1,38 +0,0 @@ -get(); - } - - /** - * The generator. - * - * @return Generator - * The finite group generator - */ - protected function get(): Generator - { - foreach ($this->group as $number) { - yield $number; - } - } -} diff --git a/src/Generators/NGrams.php b/src/Generators/NGrams.php deleted file mode 100644 index 9380e60..0000000 --- a/src/Generators/NGrams.php +++ /dev/null @@ -1,43 +0,0 @@ -get(); - } - - /** - * {@inheritdoc} - */ - public function toArray(): array - { - return []; - } - - /** - * Get the generator. - * - * @return Generator - * The generator - */ - protected function get(): Generator - { - while (true) { - $this->next(); - - yield $this->current(); - } - } -} diff --git a/src/Generators/Perfect.php b/src/Generators/Perfect.php deleted file mode 100644 index 937851b..0000000 --- a/src/Generators/Perfect.php +++ /dev/null @@ -1,23 +0,0 @@ -getMaxLimit() >= $j; ++$j) { - if ($this->isPerfectNumber($j)) { - yield $j; - } - } - } -} diff --git a/src/Generators/Permutations.php b/src/Generators/Permutations.php deleted file mode 100644 index 7b27a02..0000000 --- a/src/Generators/Permutations.php +++ /dev/null @@ -1,98 +0,0 @@ - $dataset - * The dataset - * @param int|null $length - * The length - */ - public function __construct(array $dataset = [], $length = null) - { - parent::__construct($dataset, $length); - $this->combinations = new Combinations($dataset, $this->getLength()); - } - - /** - * {@inheritdoc} - */ - public function count(): int - { - return $this->combinations->count() * $this->fact($this->getLength()); - } - - /** - * {@inheritdoc} - */ - public function generator(): Generator - { - foreach ($this->combinations->generator() as $combination) { - foreach ($this->get($combination) as $current) { - yield $current; - } - } - } - - /** - * {@inheritdoc} - */ - public function toArray(): array - { - $data = []; - - foreach ($this->generator() as $value) { - $data[] = $value; - } - - return $data; - } - - /** - * The permutations generator. - * - * @param array $dataset - * The dataset - * - * @return Generator - */ - protected function get(array $dataset): Generator - { - foreach ($dataset as $key => $firstItem) { - $remaining = $dataset; - - array_splice($remaining, $key, 1); - - if (0 === count($remaining)) { - yield [$firstItem]; - - continue; - } - - foreach ($this->get($remaining) as $permutation) { - array_unshift($permutation, $firstItem); - - yield $permutation; - } - } - } -} diff --git a/src/Generators/Prime.php b/src/Generators/Prime.php deleted file mode 100644 index 1cf436d..0000000 --- a/src/Generators/Prime.php +++ /dev/null @@ -1,23 +0,0 @@ -getMaxLimit() >= $j; ++$j) { - if ($this->isPrimeNumber($j)) { - yield $j; - } - } - } -} diff --git a/src/Generators/PrimeFactors.php b/src/Generators/PrimeFactors.php deleted file mode 100644 index 410e14a..0000000 --- a/src/Generators/PrimeFactors.php +++ /dev/null @@ -1,30 +0,0 @@ -getNumber(); - - for ($i = 2; $number / $i >= $i; ++$i) { - while (0 === $number % $i) { - yield $i; - $number /= $i; - } - } - - if (1 < $number) { - yield $number; - } - } -} diff --git a/src/Generators/Product.php b/src/Generators/Product.php deleted file mode 100644 index 4aa446a..0000000 --- a/src/Generators/Product.php +++ /dev/null @@ -1,45 +0,0 @@ -get($this->getDataset()); - } - - /** - * Get the generator. - * - * @param array $data - * The dataset - * - * @return Generator - */ - protected function get(array $data): Generator - { - if (!empty($data)) { - if ($u = array_pop($data)) { - foreach ($this->get($data) as $p) { - foreach ($u as $v) { - yield $p + [count($p) => $v]; - } - } - } - } else { - yield []; - } - } -} diff --git a/src/Generators/Shift.php b/src/Generators/Shift.php deleted file mode 100644 index 3f9a7c5..0000000 --- a/src/Generators/Shift.php +++ /dev/null @@ -1,31 +0,0 @@ -next(); - - yield $this->current(); - } - } - - /** - * {@inheritdoc} - */ - public function toArray(): array - { - return []; - } -} diff --git a/src/IteratorInterface.php b/src/IteratorInterface.php deleted file mode 100644 index a00c770..0000000 --- a/src/IteratorInterface.php +++ /dev/null @@ -1,16 +0,0 @@ - - */ -interface IteratorInterface extends Iterator -{ -} diff --git a/src/Iterators.php b/src/Iterators.php index 6f394b8..e64b4fb 100644 --- a/src/Iterators.php +++ b/src/Iterators.php @@ -5,8 +5,9 @@ namespace drupol\phpermutations; use Countable; +use Iterator; -abstract class Iterators extends Combinatorics implements Countable, IteratorInterface +abstract class Iterators extends Combinatorics implements Iterator { /** * A copy of the dataset at a give time. @@ -15,10 +16,7 @@ abstract class Iterators extends Combinatorics implements Countable, IteratorInt */ protected $current; - /** - * @var int - */ - protected $key = 0; + protected int $key = 0; /** * {@inheritdoc} @@ -45,21 +43,4 @@ public function rewind(): void { $this->key = 0; } - - /** - * Convert the iterator into an array. - * - * @return array - * The elements - */ - public function toArray(): array - { - $data = []; - - for ($this->rewind(); $this->valid(); $this->next()) { - $data[] = $this->current(); - } - - return $data; - } } diff --git a/src/Iterators/Combinations.php b/src/Iterators/Combinations.php index fd195e2..e100896 100644 --- a/src/Iterators/Combinations.php +++ b/src/Iterators/Combinations.php @@ -6,62 +6,24 @@ use drupol\phpermutations\Iterators; -class Combinations extends Iterators +final class Combinations extends Iterators { - /** - * The values. - * - * @var array - */ - protected $c = []; + private array $c = []; - /** - * Combinations constructor. - * - * @param array $dataset - * The dataset - * @param int|null $length - * The length - */ - public function __construct(array $dataset = [], $length = null) + public function __construct(array $dataset = [], ?int $length = null) { parent::__construct(array_values($dataset), $length); $this->rewind(); } - /** - * {@inheritdoc} - */ - public function count(): int - { - $i = 0; - - for ($this->rewind(); $this->valid(); $this->next()) { - ++$i; - } - - return $i; - } - - /** - * {@inheritdoc} - */ public function current(): mixed { - $r = []; - - for ($i = 0; $i < $this->length; ++$i) { - $r[] = $this->dataset[$this->c[$i]]; - } - - return $r; + return array_map( + fn(int $index): mixed => $this->dataset[$this->c[$index]], + range(0, $this->length - 1) + ); } - /** - * {@inheritdoc} - * - * @return void - */ public function next(): void { if ($this->nextHelper()) { @@ -71,32 +33,18 @@ public function next(): void } } - /** - * {@inheritdoc} - */ public function rewind(): void { $this->c = range(0, $this->length); $this->key = 0; } - /** - * {@inheritdoc} - * - * @return bool - */ public function valid(): bool { return 0 <= $this->key; } - /** - * Custom next() callback. - * - * @return bool - * Return true or false - */ - protected function nextHelper(): bool + private function nextHelper(): bool { $i = $this->length - 1; diff --git a/src/Iterators/Cycle.php b/src/Iterators/Cycle.php index 3ffadfc..9c20790 100644 --- a/src/Iterators/Cycle.php +++ b/src/Iterators/Cycle.php @@ -8,7 +8,7 @@ use function count; -class Cycle extends Iterators +final class Cycle extends Iterators { /** * {@inheritdoc} diff --git a/src/Iterators/Fibonacci.php b/src/Iterators/Fibonacci.php index 4577aff..0dd794c 100644 --- a/src/Iterators/Fibonacci.php +++ b/src/Iterators/Fibonacci.php @@ -8,61 +8,31 @@ use const PHP_INT_MAX; -class Fibonacci extends Iterators +final class Fibonacci extends Iterators { - /** - * @var int - */ protected $current; - /** - * The maximum limit. - * - * @var int - */ - protected $max; + protected int $max; - /** - * The previous element. - * - * @var int - */ - private $previous = 1; + private int $previous = 1; - /** - * Fibonacci constructor. - */ public function __construct() { $this->setMaxLimit(PHP_INT_MAX); parent::__construct(); } - /** - * Get the maximum limit. - * - * @return int - * The limit - */ public function getMaxLimit(): int { return (int) $this->max; } - /** - * {@inheritdoc} - * - * @return void - */ public function next(): void { [$this->current, $this->previous] = [$this->current + $this->previous, $this->current]; ++$this->key; } - /** - * {@inheritdoc} - */ public function rewind(): void { $this->previous = 1; @@ -72,22 +42,12 @@ public function rewind(): void /** * Set the maximum limit. - * - * @param int $max - * The limit - * - * @return void */ - public function setMaxLimit($max): void + public function setMaxLimit(int $max): void { $this->max = $max; } - /** - * {@inheritdoc} - * - * @return bool - */ public function valid(): bool { return $this->getMaxLimit() > $this->current; diff --git a/src/Iterators/FiniteGroup.php b/src/Iterators/FiniteGroup.php index 7c62ce2..5efd0d9 100644 --- a/src/Iterators/FiniteGroup.php +++ b/src/Iterators/FiniteGroup.php @@ -9,11 +9,9 @@ use function count; /** - * Class FiniteGroup. - * * The finite group is an abelian finite cyclic group. */ -class FiniteGroup extends Iterators +final class FiniteGroup extends Iterators { /** * The group. diff --git a/src/Iterators/NGrams.php b/src/Iterators/NGrams.php index 3647543..58f89e9 100644 --- a/src/Iterators/NGrams.php +++ b/src/Iterators/NGrams.php @@ -4,61 +4,42 @@ namespace drupol\phpermutations\Iterators; -use function array_slice; +use drupol\phpermutations\Iterators; -class NGrams extends Shift +final class NGrams extends Iterators { - /** - * @var mixed - */ - protected $currentValue; + private Shift $shift; - /** - * NGrams constructor. - * - * @param array $dataset - * The dataset - * @param int $length - * The shift length - */ - public function __construct(array $dataset = [], $length = 1) + protected $length; + + public function __construct(array $dataset = [], int $length = 1) { - parent::__construct($dataset, $length); + $this->shift = new Shift($dataset, $length); + $this->length = $length; + } - $this->currentValue = array_slice( - $this->getDataset(), - 0, - $length - ); + public function getDataset(): array + { + return $this->shift->getDataset(); } - /** - * {@inheritdoc} - */ public function current(): mixed { - return $this->currentValue; + return array_slice($this->shift->current(), 0, $this->length); } - /** - * {@inheritdoc} - * - * @return void - */ public function next(): void { - parent::next(); - $this->currentValue = array_slice($this->current, 0, $this->getLength()); + $this->shift->next(); } - /** - * {@inheritdoc} - * - * @return void - */ public function rewind(): void { - parent::rewind(); - $this->currentValue = array_slice($this->current, 0, $this->getLength()); + $this->shift->rewind(); + } + + public function valid(): bool + { + return $this->shift->valid(); } } diff --git a/src/Iterators/Perfect.php b/src/Iterators/Perfect.php index 7e21043..c00c4af 100644 --- a/src/Iterators/Perfect.php +++ b/src/Iterators/Perfect.php @@ -8,7 +8,7 @@ use const PHP_INT_MAX; -class Perfect extends Iterators +final class Perfect extends Iterators { /** * The maximum limit. diff --git a/src/Iterators/Prime.php b/src/Iterators/Prime.php index 916de47..d3f6512 100644 --- a/src/Iterators/Prime.php +++ b/src/Iterators/Prime.php @@ -8,7 +8,7 @@ use const PHP_INT_MAX; -class Prime extends Iterators +final class Prime extends Iterators { /** * The maximum limit. diff --git a/src/Iterators/PrimeFactors.php b/src/Iterators/PrimeFactors.php index a9a2fd5..dd6fda8 100644 --- a/src/Iterators/PrimeFactors.php +++ b/src/Iterators/PrimeFactors.php @@ -8,7 +8,7 @@ use function count; -class PrimeFactors extends Iterators +final class PrimeFactors extends Iterators { /** * The prime factors. diff --git a/src/Iterators/Product.php b/src/Iterators/Product.php index 9d9d0a0..1565b5d 100644 --- a/src/Iterators/Product.php +++ b/src/Iterators/Product.php @@ -10,7 +10,7 @@ use function count; -class Product extends Iterators +final class Product extends Iterators { /** * The iterators. diff --git a/src/Iterators/Rotation.php b/src/Iterators/Rotation.php index 9a30bc9..e78f95d 100644 --- a/src/Iterators/Rotation.php +++ b/src/Iterators/Rotation.php @@ -9,7 +9,7 @@ use function array_slice; use function count; -class Rotation extends Iterators +final class Rotation extends Iterators { /** * A copy of the original data. diff --git a/src/Iterators/Shift.php b/src/Iterators/Shift.php index af787ba..3e222a9 100644 --- a/src/Iterators/Shift.php +++ b/src/Iterators/Shift.php @@ -9,7 +9,7 @@ use function array_slice; use function count; -class Shift extends Iterators +final class Shift extends Iterators { /** * Shift constructor. diff --git a/tests/fixtures/combinations.yml b/tests/fixtures/combinations.yml index b36070b..0e4922b 100644 --- a/tests/fixtures/combinations.yml +++ b/tests/fixtures/combinations.yml @@ -1,58 +1,51 @@ -- - input: - dataset: - [1, 2, 3, 4, 5] - length: 5 - output: - dataset: - - [1, 2, 3, 4, 5] - count: 1 +- input: + dataset: [1, 2, 3, 4, 5] + length: 5 + expected: + dataset: + - [1, 2, 3, 4, 5] + count: 1 -- - input: - dataset: - [1, 2, 3, 4, 5] - length: 3 - output: - dataset: - - [1, 2, 3] - - [1, 2, 4] - - [1, 2, 5] - - [1, 3, 4] - - [1, 3, 5] - - [1, 4, 5] - - [2, 3, 4] - - [2, 3, 5] - - [2, 4, 5] - - [3, 4, 5] - count: 10 +- input: + dataset: [1, 2, 3, 4, 5] + length: 3 + expected: + dataset: + - [1, 2, 3] + - [1, 2, 4] + - [1, 2, 5] + - [1, 3, 4] + - [1, 3, 5] + - [1, 4, 5] + - [2, 3, 4] + - [2, 3, 5] + - [2, 4, 5] + - [3, 4, 5] + count: 10 -- - input: - dataset: - [1, 2, 3, 4, 5] - length: 4 - output: - dataset: - - [1, 2, 3 ,4] - - [1, 2, 3 ,5] - - [1, 2, 4 ,5] - - [1, 3, 4 ,5] - - [2, 3, 4 ,5] - count: 5 +- input: + dataset: [1, 2, 3, 4, 5] + length: 4 + expected: + dataset: + - [1, 2, 3, 4] + - [1, 2, 3, 5] + - [1, 2, 4, 5] + - [1, 3, 4, 5] + - [2, 3, 4, 5] + count: 5 -- - input: - dataset: - - ['element 1'] - - ['element 2'] - - ['element 3'] - - ['element 4'] - length: 3 - output: - dataset: - - [['element 1'], ['element 2'], ['element 3']] - - [['element 1'], ['element 2'], ['element 4']] - - [['element 1'], ['element 3'], ['element 4']] - - [['element 2'], ['element 3'], ['element 4']] - count: 4 +- input: + dataset: + - ["element 1"] + - ["element 2"] + - ["element 3"] + - ["element 4"] + length: 3 + expected: + dataset: + - [["element 1"], ["element 2"], ["element 3"]] + - [["element 1"], ["element 2"], ["element 4"]] + - [["element 1"], ["element 3"], ["element 4"]] + - [["element 2"], ["element 3"], ["element 4"]] + count: 4 diff --git a/tests/fixtures/cycle.yml b/tests/fixtures/cycle.yml index 9924a8c..d64e850 100644 --- a/tests/fixtures/cycle.yml +++ b/tests/fixtures/cycle.yml @@ -1,23 +1,20 @@ -- - input: +- input: dataset: [1, 2, 3, 4, 5] turn: 1 - output: + expected: current: 2 count: 5 -- - input: +- input: dataset: [1, 2, 3, 4, 5] turn: 6 - output: + expected: current: 2 count: 5 -- - input: +- input: dataset: [1, 2, 3, 4, 5, 6] turn: 8 - output: + expected: current: 3 count: 6 diff --git a/tests/fixtures/fibonacci.yml b/tests/fixtures/fibonacci.yml index 807b4e8..ea781ab 100644 --- a/tests/fixtures/fibonacci.yml +++ b/tests/fixtures/fibonacci.yml @@ -1,6 +1,6 @@ -- - input: +- input: max: 1000 - output: - dataset: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987] + expected: + dataset: + [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987] count: 17 diff --git a/tests/fixtures/finitegroup.yml b/tests/fixtures/finitegroup.yml index 0fde977..b3f96c2 100644 --- a/tests/fixtures/finitegroup.yml +++ b/tests/fixtures/finitegroup.yml @@ -1,6 +1,5 @@ -- - input: +- input: size: 10 - output: + expected: dataset: [1, 3, 7, 9] count: 4 diff --git a/tests/fixtures/ngrams.yml b/tests/fixtures/ngrams.yml index 2d7271f..db0e2c9 100644 --- a/tests/fixtures/ngrams.yml +++ b/tests/fixtures/ngrams.yml @@ -1,35 +1,31 @@ -- - input: +- input: dataset: [A, B, C, D, E] length: 2 turn: 1 - output: + expected: current: [E, A] count: 5 -- - input: +- input: dataset: [A, B, C, D, E] length: 3 turn: 3 - output: + expected: current: [C, D, E] count: 5 -- - input: +- input: dataset: [A, B, C, D, E] length: 2 turn: 11 - output: + expected: current: [E, A] count: 5 -- - input: +- input: dataset: [A, B, C, D, E] length: 3 turn: 13 - output: + expected: current: [C, D, E] count: 5 diff --git a/tests/fixtures/perfect.yml b/tests/fixtures/perfect.yml index b1bbfe4..d35a9e6 100644 --- a/tests/fixtures/perfect.yml +++ b/tests/fixtures/perfect.yml @@ -1,18 +1,16 @@ -- - input: +- input: min: 0 max: 1000 - output: + expected: dataset: - - 6 - - 28 - - 496 + - 6 + - 28 + - 496 count: 3 -- - input: +- input: min: 500 max: 10000 - output: + expected: dataset: - - 8128 + - 8128 count: 1 diff --git a/tests/fixtures/permutations.yml b/tests/fixtures/permutations.yml index 1879600..49acf51 100644 --- a/tests/fixtures/permutations.yml +++ b/tests/fixtures/permutations.yml @@ -1,194 +1,672 @@ -- - input: +- input: dataset: [1, 2, 3, 4, 5] length: 5 - output: + expected: dataset: - - [1, 2, 3, 4, 5] - - [2, 1, 3, 4, 5] - - [1, 3, 2, 4, 5] - - [3, 1, 2, 4, 5] - - [2, 3, 1, 4, 5] - - [3, 2, 1, 4, 5] - - [1, 2, 4, 3, 5] - - [2, 1, 4, 3, 5] - - [1, 4, 2, 3, 5] - - [4, 1, 2, 3, 5] - - [2, 4, 1, 3, 5] - - [4, 2, 1, 3, 5] - - [1, 3, 4, 2, 5] - - [3, 1, 4, 2, 5] - - [1, 4, 3, 2, 5] - - [4, 1, 3, 2, 5] - - [3, 4, 1, 2, 5] - - [4, 3, 1, 2, 5] - - [2, 3, 4, 1, 5] - - [3, 2, 4, 1, 5] - - [2, 4, 3, 1, 5] - - [4, 2, 3, 1, 5] - - [3, 4, 2, 1, 5] - - [4, 3, 2, 1, 5] - - [1, 2, 3, 5, 4] - - [2, 1, 3, 5, 4] - - [1, 3, 2, 5, 4] - - [3, 1, 2, 5, 4] - - [2, 3, 1, 5, 4] - - [3, 2, 1, 5, 4] - - [1, 2, 5, 3, 4] - - [2, 1, 5, 3, 4] - - [1, 5, 2, 3, 4] - - [5, 1, 2, 3, 4] - - [2, 5, 1, 3, 4] - - [5, 2, 1, 3, 4] - - [1, 3, 5, 2, 4] - - [3, 1, 5, 2, 4] - - [1, 5, 3, 2, 4] - - [5, 1, 3, 2, 4] - - [3, 5, 1, 2, 4] - - [5, 3, 1, 2, 4] - - [2, 3, 5, 1, 4] - - [3, 2, 5, 1, 4] - - [2, 5, 3, 1, 4] - - [5, 2, 3, 1, 4] - - [3, 5, 2, 1, 4] - - [5, 3, 2, 1, 4] - - [1, 2, 4, 5, 3] - - [2, 1, 4, 5, 3] - - [1, 4, 2, 5, 3] - - [4, 1, 2, 5, 3] - - [2, 4, 1, 5, 3] - - [4, 2, 1, 5, 3] - - [1, 2, 5, 4, 3] - - [2, 1, 5, 4, 3] - - [1, 5, 2, 4, 3] - - [5, 1, 2, 4, 3] - - [2, 5, 1, 4, 3] - - [5, 2, 1, 4, 3] - - [1, 4, 5, 2, 3] - - [4, 1, 5, 2, 3] - - [1, 5, 4, 2, 3] - - [5, 1, 4, 2, 3] - - [4, 5, 1, 2, 3] - - [5, 4, 1, 2, 3] - - [2, 4, 5, 1, 3] - - [4, 2, 5, 1, 3] - - [2, 5, 4, 1, 3] - - [5, 2, 4, 1, 3] - - [4, 5, 2, 1, 3] - - [5, 4, 2, 1, 3] - - [1, 3, 4, 5, 2] - - [3, 1, 4, 5, 2] - - [1, 4, 3, 5, 2] - - [4, 1, 3, 5, 2] - - [3, 4, 1, 5, 2] - - [4, 3, 1, 5, 2] - - [1, 3, 5, 4, 2] - - [3, 1, 5, 4, 2] - - [1, 5, 3, 4, 2] - - [5, 1, 3, 4, 2] - - [3, 5, 1, 4, 2] - - [5, 3, 1, 4, 2] - - [1, 4, 5, 3, 2] - - [4, 1, 5, 3, 2] - - [1, 5, 4, 3, 2] - - [5, 1, 4, 3, 2] - - [4, 5, 1, 3, 2] - - [5, 4, 1, 3, 2] - - [3, 4, 5, 1, 2] - - [4, 3, 5, 1, 2] - - [3, 5, 4, 1, 2] - - [5, 3, 4, 1, 2] - - [4, 5, 3, 1, 2] - - [5, 4, 3, 1, 2] - - [2, 3, 4, 5, 1] - - [3, 2, 4, 5, 1] - - [2, 4, 3, 5, 1] - - [4, 2, 3, 5, 1] - - [3, 4, 2, 5, 1] - - [4, 3, 2, 5, 1] - - [2, 3, 5, 4, 1] - - [3, 2, 5, 4, 1] - - [2, 5, 3, 4, 1] - - [5, 2, 3, 4, 1] - - [3, 5, 2, 4, 1] - - [5, 3, 2, 4, 1] - - [2, 4, 5, 3, 1] - - [4, 2, 5, 3, 1] - - [2, 5, 4, 3, 1] - - [5, 2, 4, 3, 1] - - [4, 5, 2, 3, 1] - - [5, 4, 2, 3, 1] - - [3, 4, 5, 2, 1] - - [4, 3, 5, 2, 1] - - [3, 5, 4, 2, 1] - - [5, 3, 4, 2, 1] - - [4, 5, 3, 2, 1] - - [5, 4, 3, 2, 1] + - - 1 + - 2 + - 3 + - 4 + - 5 + - - 1 + - 2 + - 3 + - 5 + - 4 + - - 1 + - 2 + - 4 + - 3 + - 5 + - - 1 + - 2 + - 4 + - 5 + - 3 + - - 1 + - 2 + - 5 + - 3 + - 4 + - - 1 + - 2 + - 5 + - 4 + - 3 + - - 1 + - 3 + - 2 + - 4 + - 5 + - - 1 + - 3 + - 2 + - 5 + - 4 + - - 1 + - 3 + - 4 + - 2 + - 5 + - - 1 + - 3 + - 4 + - 5 + - 2 + - - 1 + - 3 + - 5 + - 2 + - 4 + - - 1 + - 3 + - 5 + - 4 + - 2 + - - 1 + - 4 + - 2 + - 3 + - 5 + - - 1 + - 4 + - 2 + - 5 + - 3 + - - 1 + - 4 + - 3 + - 2 + - 5 + - - 1 + - 4 + - 3 + - 5 + - 2 + - - 1 + - 4 + - 5 + - 2 + - 3 + - - 1 + - 4 + - 5 + - 3 + - 2 + - - 1 + - 5 + - 2 + - 3 + - 4 + - - 1 + - 5 + - 2 + - 4 + - 3 + - - 1 + - 5 + - 3 + - 2 + - 4 + - - 1 + - 5 + - 3 + - 4 + - 2 + - - 1 + - 5 + - 4 + - 2 + - 3 + - - 1 + - 5 + - 4 + - 3 + - 2 + - - 2 + - 1 + - 3 + - 4 + - 5 + - - 2 + - 1 + - 3 + - 5 + - 4 + - - 2 + - 1 + - 4 + - 3 + - 5 + - - 2 + - 1 + - 4 + - 5 + - 3 + - - 2 + - 1 + - 5 + - 3 + - 4 + - - 2 + - 1 + - 5 + - 4 + - 3 + - - 2 + - 3 + - 1 + - 4 + - 5 + - - 2 + - 3 + - 1 + - 5 + - 4 + - - 2 + - 3 + - 4 + - 1 + - 5 + - - 2 + - 3 + - 4 + - 5 + - 1 + - - 2 + - 3 + - 5 + - 1 + - 4 + - - 2 + - 3 + - 5 + - 4 + - 1 + - - 2 + - 4 + - 1 + - 3 + - 5 + - - 2 + - 4 + - 1 + - 5 + - 3 + - - 2 + - 4 + - 3 + - 1 + - 5 + - - 2 + - 4 + - 3 + - 5 + - 1 + - - 2 + - 4 + - 5 + - 1 + - 3 + - - 2 + - 4 + - 5 + - 3 + - 1 + - - 2 + - 5 + - 1 + - 3 + - 4 + - - 2 + - 5 + - 1 + - 4 + - 3 + - - 2 + - 5 + - 3 + - 1 + - 4 + - - 2 + - 5 + - 3 + - 4 + - 1 + - - 2 + - 5 + - 4 + - 1 + - 3 + - - 2 + - 5 + - 4 + - 3 + - 1 + - - 3 + - 1 + - 2 + - 4 + - 5 + - - 3 + - 1 + - 2 + - 5 + - 4 + - - 3 + - 1 + - 4 + - 2 + - 5 + - - 3 + - 1 + - 4 + - 5 + - 2 + - - 3 + - 1 + - 5 + - 2 + - 4 + - - 3 + - 1 + - 5 + - 4 + - 2 + - - 3 + - 2 + - 1 + - 4 + - 5 + - - 3 + - 2 + - 1 + - 5 + - 4 + - - 3 + - 2 + - 4 + - 1 + - 5 + - - 3 + - 2 + - 4 + - 5 + - 1 + - - 3 + - 2 + - 5 + - 1 + - 4 + - - 3 + - 2 + - 5 + - 4 + - 1 + - - 3 + - 4 + - 1 + - 2 + - 5 + - - 3 + - 4 + - 1 + - 5 + - 2 + - - 3 + - 4 + - 2 + - 1 + - 5 + - - 3 + - 4 + - 2 + - 5 + - 1 + - - 3 + - 4 + - 5 + - 1 + - 2 + - - 3 + - 4 + - 5 + - 2 + - 1 + - - 3 + - 5 + - 1 + - 2 + - 4 + - - 3 + - 5 + - 1 + - 4 + - 2 + - - 3 + - 5 + - 2 + - 1 + - 4 + - - 3 + - 5 + - 2 + - 4 + - 1 + - - 3 + - 5 + - 4 + - 1 + - 2 + - - 3 + - 5 + - 4 + - 2 + - 1 + - - 4 + - 1 + - 2 + - 3 + - 5 + - - 4 + - 1 + - 2 + - 5 + - 3 + - - 4 + - 1 + - 3 + - 2 + - 5 + - - 4 + - 1 + - 3 + - 5 + - 2 + - - 4 + - 1 + - 5 + - 2 + - 3 + - - 4 + - 1 + - 5 + - 3 + - 2 + - - 4 + - 2 + - 1 + - 3 + - 5 + - - 4 + - 2 + - 1 + - 5 + - 3 + - - 4 + - 2 + - 3 + - 1 + - 5 + - - 4 + - 2 + - 3 + - 5 + - 1 + - - 4 + - 2 + - 5 + - 1 + - 3 + - - 4 + - 2 + - 5 + - 3 + - 1 + - - 4 + - 3 + - 1 + - 2 + - 5 + - - 4 + - 3 + - 1 + - 5 + - 2 + - - 4 + - 3 + - 2 + - 1 + - 5 + - - 4 + - 3 + - 2 + - 5 + - 1 + - - 4 + - 3 + - 5 + - 1 + - 2 + - - 4 + - 3 + - 5 + - 2 + - 1 + - - 4 + - 5 + - 1 + - 2 + - 3 + - - 4 + - 5 + - 1 + - 3 + - 2 + - - 4 + - 5 + - 2 + - 1 + - 3 + - - 4 + - 5 + - 2 + - 3 + - 1 + - - 4 + - 5 + - 3 + - 1 + - 2 + - - 4 + - 5 + - 3 + - 2 + - 1 + - - 5 + - 1 + - 2 + - 3 + - 4 + - - 5 + - 1 + - 2 + - 4 + - 3 + - - 5 + - 1 + - 3 + - 2 + - 4 + - - 5 + - 1 + - 3 + - 4 + - 2 + - - 5 + - 1 + - 4 + - 2 + - 3 + - - 5 + - 1 + - 4 + - 3 + - 2 + - - 5 + - 2 + - 1 + - 3 + - 4 + - - 5 + - 2 + - 1 + - 4 + - 3 + - - 5 + - 2 + - 3 + - 1 + - 4 + - - 5 + - 2 + - 3 + - 4 + - 1 + - - 5 + - 2 + - 4 + - 1 + - 3 + - - 5 + - 2 + - 4 + - 3 + - 1 + - - 5 + - 3 + - 1 + - 2 + - 4 + - - 5 + - 3 + - 1 + - 4 + - 2 + - - 5 + - 3 + - 2 + - 1 + - 4 + - - 5 + - 3 + - 2 + - 4 + - 1 + - - 5 + - 3 + - 4 + - 1 + - 2 + - - 5 + - 3 + - 4 + - 2 + - 1 + - - 5 + - 4 + - 1 + - 2 + - 3 + - - 5 + - 4 + - 1 + - 3 + - 2 + - - 5 + - 4 + - 2 + - 1 + - 3 + - - 5 + - 4 + - 2 + - 3 + - 1 + - - 5 + - 4 + - 3 + - 1 + - 2 + - - 5 + - 4 + - 3 + - 2 + - 1 count: 120 -- - input: +- input: dataset: [1, 2, 3, 4, 5] length: 3 - output: + expected: dataset: - - [1, 2, 3] - - [1, 3, 2] - - [2, 1, 3] - - [2, 3, 1] - - [3, 1, 2] - - [3, 2, 1] - - [1, 2, 4] - - [1, 4, 2] - - [2, 1, 4] - - [2, 4, 1] - - [4, 1, 2] - - [4, 2, 1] - - [1, 2, 5] - - [1, 5, 2] - - [2, 1, 5] - - [2, 5, 1] - - [5, 1, 2] - - [5, 2, 1] - - [1, 3, 4] - - [1, 4, 3] - - [3, 1, 4] - - [3, 4, 1] - - [4, 1, 3] - - [4, 3, 1] - - [1, 3, 5] - - [1, 5, 3] - - [3, 1, 5] - - [3, 5, 1] - - [5, 1, 3] - - [5, 3, 1] - - [1, 4, 5] - - [1, 5, 4] - - [4, 1, 5] - - [4, 5, 1] - - [5, 1, 4] - - [5, 4, 1] - - [2, 3, 4] - - [2, 4, 3] - - [3, 2, 4] - - [3, 4, 2] - - [4, 2, 3] - - [4, 3, 2] - - [2, 3, 5] - - [2, 5, 3] - - [3, 2, 5] - - [3, 5, 2] - - [5, 2, 3] - - [5, 3, 2] - - [2, 4, 5] - - [2, 5, 4] - - [4, 2, 5] - - [4, 5, 2] - - [5, 2, 4] - - [5, 4, 2] - - [3, 4, 5] - - [3, 5, 4] - - [4, 3, 5] - - [4, 5, 3] - - [5, 3, 4] - - [5, 4, 3] + - [1, 2, 3] + - [1, 3, 2] + - [2, 1, 3] + - [2, 3, 1] + - [3, 1, 2] + - [3, 2, 1] + - [1, 2, 4] + - [1, 4, 2] + - [2, 1, 4] + - [2, 4, 1] + - [4, 1, 2] + - [4, 2, 1] + - [1, 2, 5] + - [1, 5, 2] + - [2, 1, 5] + - [2, 5, 1] + - [5, 1, 2] + - [5, 2, 1] + - [1, 3, 4] + - [1, 4, 3] + - [3, 1, 4] + - [3, 4, 1] + - [4, 1, 3] + - [4, 3, 1] + - [1, 3, 5] + - [1, 5, 3] + - [3, 1, 5] + - [3, 5, 1] + - [5, 1, 3] + - [5, 3, 1] + - [1, 4, 5] + - [1, 5, 4] + - [4, 1, 5] + - [4, 5, 1] + - [5, 1, 4] + - [5, 4, 1] + - [2, 3, 4] + - [2, 4, 3] + - [3, 2, 4] + - [3, 4, 2] + - [4, 2, 3] + - [4, 3, 2] + - [2, 3, 5] + - [2, 5, 3] + - [3, 2, 5] + - [3, 5, 2] + - [5, 2, 3] + - [5, 3, 2] + - [2, 4, 5] + - [2, 5, 4] + - [4, 2, 5] + - [4, 5, 2] + - [5, 2, 4] + - [5, 4, 2] + - [3, 4, 5] + - [3, 5, 4] + - [4, 3, 5] + - [4, 5, 3] + - [5, 3, 4] + - [5, 4, 3] count: 60 diff --git a/tests/fixtures/prime.yml b/tests/fixtures/prime.yml index c46b34c..0d38e52 100644 --- a/tests/fixtures/prime.yml +++ b/tests/fixtures/prime.yml @@ -1,14 +1,182 @@ -- - input: +- input: min: 1 max: 1000 - output: - dataset: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997] + expected: + dataset: + [ + 2, + 3, + 5, + 7, + 11, + 13, + 17, + 19, + 23, + 29, + 31, + 37, + 41, + 43, + 47, + 53, + 59, + 61, + 67, + 71, + 73, + 79, + 83, + 89, + 97, + 101, + 103, + 107, + 109, + 113, + 127, + 131, + 137, + 139, + 149, + 151, + 157, + 163, + 167, + 173, + 179, + 181, + 191, + 193, + 197, + 199, + 211, + 223, + 227, + 229, + 233, + 239, + 241, + 251, + 257, + 263, + 269, + 271, + 277, + 281, + 283, + 293, + 307, + 311, + 313, + 317, + 331, + 337, + 347, + 349, + 353, + 359, + 367, + 373, + 379, + 383, + 389, + 397, + 401, + 409, + 419, + 421, + 431, + 433, + 439, + 443, + 449, + 457, + 461, + 463, + 467, + 479, + 487, + 491, + 499, + 503, + 509, + 521, + 523, + 541, + 547, + 557, + 563, + 569, + 571, + 577, + 587, + 593, + 599, + 601, + 607, + 613, + 617, + 619, + 631, + 641, + 643, + 647, + 653, + 659, + 661, + 673, + 677, + 683, + 691, + 701, + 709, + 719, + 727, + 733, + 739, + 743, + 751, + 757, + 761, + 769, + 773, + 787, + 797, + 809, + 811, + 821, + 823, + 827, + 829, + 839, + 853, + 857, + 859, + 863, + 877, + 881, + 883, + 887, + 907, + 911, + 919, + 929, + 937, + 941, + 947, + 953, + 967, + 971, + 977, + 983, + 991, + 997, + ] count: 168 -- - input: +- input: min: 50 max: 100 - output: + expected: dataset: [53, 59, 61, 67, 71, 73, 79, 83, 89, 97] count: 10 diff --git a/tests/fixtures/primefactors.yml b/tests/fixtures/primefactors.yml index 4c7c582..d0b5468 100644 --- a/tests/fixtures/primefactors.yml +++ b/tests/fixtures/primefactors.yml @@ -1,18 +1,15 @@ -- - input: +- input: number: 643455 - output: + expected: dataset: [3, 3, 5, 79, 181] count: 5 -- - input: +- input: number: 29 - output: + expected: dataset: [29] count: 1 -- - input: +- input: number: 100 - output: + expected: dataset: [2, 2, 5, 5] count: 4 diff --git a/tests/fixtures/product.yml b/tests/fixtures/product.yml index b2877b9..85050fb 100644 --- a/tests/fixtures/product.yml +++ b/tests/fixtures/product.yml @@ -1,53 +1,63 @@ -- - input: +- input: dataset: - - [1, 2, 3, 4, 5] - - [1, 2, 3, 4, 5] - output: + - [1, 2, 3, 4, 5] + - [1, 2, 3, 4, 5] + expected: dataset: - - [1, 1] - - [1, 2] - - [1, 3] - - [1, 4] - - [1, 5] - - [2, 1] - - [2, 2] - - [2, 3] - - [2, 4] - - [2, 5] - - [3, 1] - - [3, 2] - - [3, 3] - - [3, 4] - - [3, 5] - - [4, 1] - - [4, 2] - - [4, 3] - - [4, 4] - - [4, 5] - - [5, 1] - - [5, 2] - - [5, 3] - - [5, 4] - - [5, 5] + - [1, 1] + - [1, 2] + - [1, 3] + - [1, 4] + - [1, 5] + - [2, 1] + - [2, 2] + - [2, 3] + - [2, 4] + - [2, 5] + - [3, 1] + - [3, 2] + - [3, 3] + - [3, 4] + - [3, 5] + - [4, 1] + - [4, 2] + - [4, 3] + - [4, 4] + - [4, 5] + - [5, 1] + - [5, 2] + - [5, 3] + - [5, 4] + - [5, 5] count: 25 -- - input: +- input: dataset: - - [1, 2, 3, 4] - - [1, 2, 3] - output: + - [1, 2, 3, 4] + - [1, 2, 3] + expected: dataset: - - [1, 1] - - [2, 1] - - [3, 1] - - [4, 1] - - [1, 2] - - [2, 2] - - [3, 2] - - [4, 2] - - [1, 3] - - [2, 3] - - [3, 3] - - [4, 3] + - - 1 + - 1 + - - 1 + - 2 + - - 1 + - 3 + - - 2 + - 1 + - - 2 + - 2 + - - 2 + - 3 + - - 3 + - 1 + - - 3 + - 2 + - - 3 + - 3 + - - 4 + - 1 + - - 4 + - 2 + - - 4 + - 3 count: 12 diff --git a/tests/fixtures/rotation.yml b/tests/fixtures/rotation.yml index 06c94ff..861d18e 100644 --- a/tests/fixtures/rotation.yml +++ b/tests/fixtures/rotation.yml @@ -1,29 +1,24 @@ -- - input: +- input: dataset: [1, 2, 3, 4, 5] - output: + expected: dataset: [2, 3, 4, 5, 1] -- - input: +- input: dataset: [1, 2, 3, 4, 5] turn: 0 - output: + expected: dataset: [1, 2, 3, 4, 5] -- - input: +- input: dataset: [1, 2, 3, 4, 5] turn: 1 - output: + expected: dataset: [2, 3, 4, 5, 1] -- - input: +- input: dataset: [1, 2, 3, 4, 5] turn: 6 - output: + expected: dataset: [2, 3, 4, 5, 1] -- - input: +- input: dataset: [1, 2, 3, 4, 5] turn: 5 - output: + expected: dataset: [1, 2, 3, 4, 5] diff --git a/tests/fixtures/shift.yml b/tests/fixtures/shift.yml index b565a27..8a6575c 100644 --- a/tests/fixtures/shift.yml +++ b/tests/fixtures/shift.yml @@ -1,31 +1,27 @@ -- - input: +- input: dataset: [A, B, C, D, E] turn: 1 - output: + expected: current: [E, A, B, C, D] count: 5 -- - input: +- input: dataset: [A, B, C, D, E] turn: 3 - output: + expected: current: [C, D, E, A, B] count: 5 -- - input: +- input: dataset: [A, B, C, D, E] turn: 10 - output: + expected: current: [A, B, C, D, E] count: 5 -- - input: +- input: dataset: [A, B, C, D, E] turn: 13 - output: + expected: current: [C, D, E, A, B] count: 5 diff --git a/tests/phpunit.xml b/tests/phpunit.xml deleted file mode 100644 index 3d02efc..0000000 --- a/tests/phpunit.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - ./src/ - - - - - - ./vendor - - - ../src - - - diff --git a/tests/src/AbstractTest.php b/tests/src/AbstractTester.php similarity index 79% rename from tests/src/AbstractTest.php rename to tests/src/AbstractTester.php index e2f6be0..9a5fbb2 100644 --- a/tests/src/AbstractTest.php +++ b/tests/src/AbstractTester.php @@ -13,7 +13,7 @@ * * @internal */ -abstract class AbstractTest extends TestCase +abstract class AbstractTester extends TestCase { /** * The type. @@ -26,12 +26,12 @@ abstract class AbstractTest extends TestCase * @return array * The test input values and their expected output */ - public function dataProvider() + public static function dataProvider() { - $fixtures = $this->fixtureProvider(); + $fixtures = self::fixtureProvider(); - if (isset($fixtures[$this::TYPE]['content'])) { - return $fixtures[$this::TYPE]['content']; + if (isset($fixtures[static::TYPE]['content'])) { + return $fixtures[static::TYPE]['content']; } return []; @@ -43,7 +43,7 @@ public function dataProvider() * @return array * List of component fixtures */ - public function fixtureProvider() + public static function fixtureProvider() { $data = []; diff --git a/tests/src/Generators/CombinationsTest.php b/tests/src/Generators/CombinationsTest.php deleted file mode 100644 index b034e1b..0000000 --- a/tests/src/Generators/CombinationsTest.php +++ /dev/null @@ -1,47 +0,0 @@ -getDataset()); - self::assertSame($input['length'], $combinations->getLength()); - self::assertEquals( - $expected['dataset'], - $combinations->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true - ); - self::assertSame($expected['count'], $combinations->count()); - } -} diff --git a/tests/src/Generators/FibonacciTest.php b/tests/src/Generators/FibonacciTest.php deleted file mode 100644 index 9489897..0000000 --- a/tests/src/Generators/FibonacciTest.php +++ /dev/null @@ -1,46 +0,0 @@ -setMaxLimit(1000); - - self::assertSame($expected['count'], $prime->count()); - self::assertEquals( - $expected['dataset'], - $prime->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true - ); - } -} diff --git a/tests/src/Generators/FiniteGroupTest.php b/tests/src/Generators/FiniteGroupTest.php deleted file mode 100644 index 631877a..0000000 --- a/tests/src/Generators/FiniteGroupTest.php +++ /dev/null @@ -1,46 +0,0 @@ -setSize($input['size']); - - self::assertSame($expected['count'], $prime->count()); - self::assertEquals( - $expected['dataset'], - $prime->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true - ); - } -} diff --git a/tests/src/Generators/PerfectTest.php b/tests/src/Generators/PerfectTest.php deleted file mode 100644 index c3f674a..0000000 --- a/tests/src/Generators/PerfectTest.php +++ /dev/null @@ -1,53 +0,0 @@ -setMinLimit($input['min']); - $perfect->setMaxLimit($input['max']); - - if (2 > $input['min']) { - self::assertSame(2, $perfect->getMinLimit()); - } else { - self::assertSame($input['min'], $perfect->getMinLimit()); - } - self::assertSame($input['max'], $perfect->getMaxLimit()); - self::assertSame($expected['count'], $perfect->count()); - self::assertEquals( - $expected['dataset'], - $perfect->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true - ); - } -} diff --git a/tests/src/Generators/PermutationsTest.php b/tests/src/Generators/PermutationsTest.php deleted file mode 100644 index db11c2d..0000000 --- a/tests/src/Generators/PermutationsTest.php +++ /dev/null @@ -1,48 +0,0 @@ -getDataset()); - self::assertSame($input['length'], $generator->getLength()); - self::assertSame($expected['count'], $generator->count()); - self::assertEquals( - $expected['dataset'], - $generator->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true - ); - } -} diff --git a/tests/src/Generators/PrimeFactorsTest.php b/tests/src/Generators/PrimeFactorsTest.php deleted file mode 100644 index e2bb49b..0000000 --- a/tests/src/Generators/PrimeFactorsTest.php +++ /dev/null @@ -1,46 +0,0 @@ -setNumber($input['number']); - - self::assertSame($expected['count'], $prime->count()); - self::assertEquals( - $expected['dataset'], - $prime->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true - ); - } -} diff --git a/tests/src/Generators/PrimeTest.php b/tests/src/Generators/PrimeTest.php deleted file mode 100644 index 5f33acf..0000000 --- a/tests/src/Generators/PrimeTest.php +++ /dev/null @@ -1,54 +0,0 @@ -setMinLimit($input['min']); - $prime->setMaxLimit($input['max']); - - if (2 > $input['min']) { - self::assertSame(2, $prime->getMinLimit()); - } else { - self::assertSame($input['min'], $prime->getMinLimit()); - } - self::assertSame($input['max'], $prime->getMaxLimit()); - - self::assertSame($expected['count'], $prime->count()); - self::assertEquals( - $expected['dataset'], - $prime->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true - ); - } -} diff --git a/tests/src/Generators/ProductTest.php b/tests/src/Generators/ProductTest.php deleted file mode 100644 index f3729ab..0000000 --- a/tests/src/Generators/ProductTest.php +++ /dev/null @@ -1,46 +0,0 @@ -getDataset()); - self::assertSame($expected['count'], $product->count()); - self::assertEquals( - $expected['dataset'], - $product->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true - ); - } -} diff --git a/tests/src/Generators/ShiftTest.php b/tests/src/Generators/ShiftTest.php deleted file mode 100644 index 11af0b4..0000000 --- a/tests/src/Generators/ShiftTest.php +++ /dev/null @@ -1,38 +0,0 @@ -getDataset()); - self::assertSame($expected['count'], $shift->count()); - } -} diff --git a/tests/src/Iterators/CombinationsTest.php b/tests/src/Iterators/CombinationsTest.php index 2e8af4e..a35d394 100644 --- a/tests/src/Iterators/CombinationsTest.php +++ b/tests/src/Iterators/CombinationsTest.php @@ -5,30 +5,18 @@ namespace drupol\phpermutations\Tests\Iterators; use drupol\phpermutations\Iterators\Combinations; -use drupol\phpermutations\Tests\AbstractTest; +use drupol\phpermutations\Tests\AbstractTester; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; + use function count; -/** - * Class CombinationsTest. - * - * @internal - * @covers \drupol\phpermutations\Iterators\Combinations - */ -final class CombinationsTest extends AbstractTest +#[CoversClass(Combinations::class)] +final class CombinationsTest extends AbstractTester { - /** - * The type. - */ public const TYPE = 'combinations'; - /** - * The tests. - * - * @dataProvider dataProvider - * - * @param mixed $input - * @param mixed $expected - */ + #[DataProvider('dataProvider')] public function testCombinations($input, $expected) { $combinations = new Combinations($input['dataset'], $input['length']); @@ -39,15 +27,15 @@ public function testCombinations($input, $expected) count($input['dataset']), $combinations->getDataset() ); + + $array = iterator_to_array($combinations, false); + self::assertEquals( $expected['dataset'], - $combinations->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true + $array, ); - self::assertSame($expected['count'], $combinations->count()); + + self::assertCount($expected['count'], $array); } /** @@ -58,6 +46,8 @@ public function testCombinations($input, $expected) public function testCombinationsWithBigNumbers() { $combinations = new Combinations(range(1, 200), 2); - self::assertCount($combinations->count(), $combinations->toArray()); + $array = iterator_to_array($combinations, false); + + self::assertCount(19900, $array); } } diff --git a/tests/src/Iterators/CycleTest.php b/tests/src/Iterators/CycleTest.php index e5236a8..8f0bd3a 100644 --- a/tests/src/Iterators/CycleTest.php +++ b/tests/src/Iterators/CycleTest.php @@ -5,29 +5,16 @@ namespace drupol\phpermutations\Tests\Iterators; use drupol\phpermutations\Iterators\Cycle; -use drupol\phpermutations\Tests\AbstractTest; +use drupol\phpermutations\Tests\AbstractTester; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; -/** - * Class CycleTest. - * - * @internal - * @covers \drupol\phpermutations\Iterators\Cycle - */ -final class CycleTest extends AbstractTest +#[CoversClass(Cycle::class)] +final class CycleTest extends AbstractTester { - /** - * The type. - */ public const TYPE = 'cycle'; - /** - * The tests. - * - * @dataProvider dataProvider - * - * @param mixed $input - * @param mixed $expected - */ + #[DataProvider('dataProvider')] public function testCycle($input, $expected) { $cycle = new Cycle($input['dataset']); diff --git a/tests/src/Iterators/FibonacciTest.php b/tests/src/Iterators/FibonacciTest.php index 969af9d..1661a87 100644 --- a/tests/src/Iterators/FibonacciTest.php +++ b/tests/src/Iterators/FibonacciTest.php @@ -5,42 +5,27 @@ namespace drupol\phpermutations\Tests\Iterators; use drupol\phpermutations\Iterators\Fibonacci; -use drupol\phpermutations\Tests\AbstractTest; +use drupol\phpermutations\Tests\AbstractTester; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; -/** - * Class FibonacciTest. - * - * @internal - * @covers \drupol\phpermutations\Iterators\Fibonacci - */ -final class FibonacciTest extends AbstractTest +#[CoversClass(Fibonacci::class)] +final class FibonacciTest extends AbstractTester { - /** - * The type. - */ public const TYPE = 'fibonacci'; - /** - * The tests. - * - * @dataProvider dataProvider - * - * @param mixed $input - * @param mixed $expected - */ + #[DataProvider('dataProvider')] public function testFibonacci($input, $expected) { $prime = new Fibonacci(); $prime->setMaxLimit(1000); - self::assertSame($expected['count'], $prime->count()); + $array = iterator_to_array($prime, false); + + self::assertCount($expected['count'], $array); self::assertEquals( $expected['dataset'], - $prime->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true + $array, ); } } diff --git a/tests/src/Iterators/FiniteGroupTest.php b/tests/src/Iterators/FiniteGroupTest.php index bff2bfe..40731a1 100644 --- a/tests/src/Iterators/FiniteGroupTest.php +++ b/tests/src/Iterators/FiniteGroupTest.php @@ -5,42 +5,26 @@ namespace drupol\phpermutations\Tests\Iterators; use drupol\phpermutations\Iterators\FiniteGroup; -use drupol\phpermutations\Tests\AbstractTest; +use drupol\phpermutations\Tests\AbstractTester; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; -/** - * Class FiniteGroupTest. - * - * @internal - * @covers \drupol\phpermutations\Iterators\FiniteGroup - */ -final class FiniteGroupTest extends AbstractTest +#[CoversClass(FiniteGroup::class)] +final class FiniteGroupTest extends AbstractTester { - /** - * The type. - */ public const TYPE = 'finitegroup'; - /** - * The tests. - * - * @dataProvider dataProvider - * - * @param mixed $input - * @param mixed $expected - */ + #[DataProvider('dataProvider')] public function testFiniteGroup($input, $expected) { $prime = new FiniteGroup(); $prime->setSize($input['size']); + $array = iterator_to_array($prime, false); - self::assertSame($expected['count'], $prime->count()); + self::assertCount($expected['count'], $array); self::assertEquals( $expected['dataset'], - $prime->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true + $array, ); } } diff --git a/tests/src/Iterators/NgramsTest.php b/tests/src/Iterators/NgramsTest.php index c158c54..a64a33a 100644 --- a/tests/src/Iterators/NgramsTest.php +++ b/tests/src/Iterators/NgramsTest.php @@ -5,29 +5,18 @@ namespace drupol\phpermutations\Tests\Iterators; use drupol\phpermutations\Iterators\NGrams; -use drupol\phpermutations\Tests\AbstractTest; +use drupol\phpermutations\Iterators\Shift; +use drupol\phpermutations\Tests\AbstractTester; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; -/** - * Class NgramsTest. - * - * @internal - * @covers \drupol\phpermutations\Iterators\NGrams - */ -final class NgramsTest extends AbstractTest +#[CoversClass(NGrams::class)] +#[CoversClass(Shift::class)] +final class NgramsTest extends AbstractTester { - /** - * The type. - */ public const TYPE = 'ngrams'; - /** - * The tests. - * - * @dataProvider dataProvider - * - * @param mixed $input - * @param mixed $expected - */ + #[DataProvider('dataProvider')] public function testNgrams($input, $expected) { $ngrams = new NGrams($input['dataset'], $input['length']); @@ -35,9 +24,8 @@ public function testNgrams($input, $expected) for ($i = 0; $i < $input['turn']; ++$i) { $ngrams->next(); } - self::assertSame($expected['current'], $ngrams->current()); + self::assertSame($expected['current'], $ngrams->current()); self::assertSame($input['dataset'], $ngrams->getDataset()); - self::assertSame($expected['count'], $ngrams->count()); } } diff --git a/tests/src/Iterators/PerfectTest.php b/tests/src/Iterators/PerfectTest.php index 71af1ff..1a0a3d8 100644 --- a/tests/src/Iterators/PerfectTest.php +++ b/tests/src/Iterators/PerfectTest.php @@ -5,34 +5,22 @@ namespace drupol\phpermutations\Tests\Iterators; use drupol\phpermutations\Iterators\Perfect; -use drupol\phpermutations\Tests\AbstractTest; +use drupol\phpermutations\Tests\AbstractTester; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; -/** - * Class PerfectTest. - * - * @internal - * @covers \drupol\phpermutations\Iterators\Perfect - */ -final class PerfectTest extends AbstractTest +#[CoversClass(Perfect::class)] +final class PerfectTest extends AbstractTester { - /** - * The type. - */ public const TYPE = 'perfect'; - /** - * The tests. - * - * @dataProvider dataProvider - * - * @param mixed $input - * @param mixed $expected - */ + #[DataProvider('dataProvider')] public function testPerfect($input, $expected) { $perfect = new Perfect(); $perfect->setMinLimit($input['min']); $perfect->setMaxLimit($input['max']); + $array = iterator_to_array($perfect, false); if (2 > $input['min']) { self::assertSame(2, $perfect->getMinLimit()); @@ -41,14 +29,10 @@ public function testPerfect($input, $expected) } self::assertSame($input['max'], $perfect->getMaxLimit()); self::assertSame($input['max'], $perfect->getMaxLimit()); - self::assertSame($expected['count'], $perfect->count()); + self::assertCount($expected['count'], $array); self::assertEquals( $expected['dataset'], - $perfect->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true + $array, ); } } diff --git a/tests/src/Iterators/PrimeFactorsTest.php b/tests/src/Iterators/PrimeFactorsTest.php index fe32d4d..0fd115e 100644 --- a/tests/src/Iterators/PrimeFactorsTest.php +++ b/tests/src/Iterators/PrimeFactorsTest.php @@ -5,42 +5,26 @@ namespace drupol\phpermutations\Tests\Iterators; use drupol\phpermutations\Iterators\PrimeFactors; -use drupol\phpermutations\Tests\AbstractTest; +use drupol\phpermutations\Tests\AbstractTester; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; -/** - * Class PrimeFactorsTest. - * - * @internal - * @covers \drupol\phpermutations\Iterators\PrimeFactors - */ -final class PrimeFactorsTest extends AbstractTest +#[CoversClass(PrimeFactors::class)] +final class PrimeFactorsTest extends AbstractTester { - /** - * The type. - */ public const TYPE = 'primefactors'; - /** - * The tests. - * - * @dataProvider dataProvider - * - * @param mixed $input - * @param mixed $expected - */ + #[DataProvider('dataProvider')] public function testPrimeFactors($input, $expected) { $prime = new PrimeFactors(); $prime->setNumber($input['number']); + $array = iterator_to_array($prime, false); - self::assertSame($expected['count'], $prime->count()); + self::assertCount($expected['count'], $array); self::assertEquals( $expected['dataset'], - $prime->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true + $array, ); } } diff --git a/tests/src/Iterators/PrimeTest.php b/tests/src/Iterators/PrimeTest.php index fa582cf..ca5458b 100644 --- a/tests/src/Iterators/PrimeTest.php +++ b/tests/src/Iterators/PrimeTest.php @@ -5,34 +5,22 @@ namespace drupol\phpermutations\Tests\Iterators; use drupol\phpermutations\Iterators\Prime; -use drupol\phpermutations\Tests\AbstractTest; +use drupol\phpermutations\Tests\AbstractTester; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; -/** - * Class PrimeTest. - * - * @internal - * @covers \drupol\phpermutations\Iterators\Prime - */ -final class PrimeTest extends AbstractTest +#[CoversClass(Prime::class)] +final class PrimeTest extends AbstractTester { - /** - * The type. - */ public const TYPE = 'prime'; - /** - * The tests. - * - * @dataProvider dataProvider - * - * @param mixed $input - * @param mixed $expected - */ + #[DataProvider('dataProvider')] public function testPrime($input, $expected) { $prime = new Prime(); $prime->setMinLimit($input['min']); $prime->setMaxLimit($input['max']); + $array = iterator_to_array($prime, false); if (2 > $input['min']) { self::assertSame(2, $prime->getMinLimit()); @@ -40,14 +28,10 @@ public function testPrime($input, $expected) self::assertSame($input['min'], $prime->getMinLimit()); } self::assertSame($input['max'], $prime->getMaxLimit()); - self::assertSame($expected['count'], $prime->count()); + self::assertCount($expected['count'], $array); self::assertEquals( $expected['dataset'], - $prime->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true + $array, ); } } diff --git a/tests/src/Iterators/ProductTest.php b/tests/src/Iterators/ProductTest.php index 1ae52ee..73610ae 100644 --- a/tests/src/Iterators/ProductTest.php +++ b/tests/src/Iterators/ProductTest.php @@ -5,42 +5,26 @@ namespace drupol\phpermutations\Tests\Iterators; use drupol\phpermutations\Iterators\Product; -use drupol\phpermutations\Tests\AbstractTest; +use drupol\phpermutations\Tests\AbstractTester; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; -/** - * Class ProductTest. - * - * @internal - * @covers \drupol\phpermutations\Iterators\Product - */ -final class ProductTest extends AbstractTest +#[CoversClass(Product::class)] +final class ProductTest extends AbstractTester { - /** - * The type. - */ public const TYPE = 'product'; - /** - * The tests. - * - * @dataProvider dataProvider - * - * @param mixed $input - * @param mixed $expected - */ + #[DataProvider('dataProvider')] public function testProduct($input, $expected) { $product = new Product($input['dataset']); + $array = iterator_to_array($product, false); + self::assertCount($expected['count'], $array); self::assertSame($input['dataset'], $product->getDataset()); self::assertEquals( $expected['dataset'], - $product->toArray(), - '$canonicalize = true', - $delta = 0.0, - $maxDepth = 10, - $canonicalize = true + $array, ); - self::assertSame($expected['count'], $product->count()); } } diff --git a/tests/src/Iterators/RotationTest.php b/tests/src/Iterators/RotationTest.php index 8bcec33..bc6fc63 100644 --- a/tests/src/Iterators/RotationTest.php +++ b/tests/src/Iterators/RotationTest.php @@ -5,30 +5,18 @@ namespace drupol\phpermutations\Tests\Iterators; use drupol\phpermutations\Iterators\Rotation; -use drupol\phpermutations\Tests\AbstractTest; +use drupol\phpermutations\Tests\AbstractTester; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; + use function count; -/** - * Class RotationTest. - * - * @internal - * @covers \drupol\phpermutations\Iterators\Rotation - */ -final class RotationTest extends AbstractTest +#[CoversClass(Rotation::class)] +final class RotationTest extends AbstractTester { - /** - * The type. - */ public const TYPE = 'rotation'; - /** - * The tests. - * - * @dataProvider dataProvider - * - * @param mixed $input - * @param mixed $expected - */ + #[DataProvider('dataProvider')] public function testRotation($input, $expected) { $rotation = new Rotation($input['dataset']); diff --git a/tests/src/Iterators/ShiftTest.php b/tests/src/Iterators/ShiftTest.php index 48a718d..f349cba 100644 --- a/tests/src/Iterators/ShiftTest.php +++ b/tests/src/Iterators/ShiftTest.php @@ -5,29 +5,16 @@ namespace drupol\phpermutations\Tests\Iterators; use drupol\phpermutations\Iterators\Shift; -use drupol\phpermutations\Tests\AbstractTest; +use drupol\phpermutations\Tests\AbstractTester; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; -/** - * Class ShiftTest. - * - * @internal - * @covers \drupol\phpermutations\Iterators\Shift - */ -final class ShiftTest extends AbstractTest +#[CoversClass(Shift::class)] +final class ShiftTest extends AbstractTester { - /** - * The type. - */ public const TYPE = 'shift'; - /** - * The tests. - * - * @dataProvider dataProvider - * - * @param mixed $input - * @param mixed $expected - */ + #[DataProvider('dataProvider')] public function testShift($input, $expected) { $shift = new Shift($input['dataset']);