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/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..59fb290 100644 --- a/src/Combinatorics.php +++ b/src/Combinatorics.php @@ -44,17 +44,6 @@ public function __construct(array $dataset = [], $length = null) $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. * @@ -108,14 +97,6 @@ public function setLength($length = null): Combinatorics return $this; } - /** - * @return array - */ - public function toArray(): array - { - return []; - } - /** * Compute the factorial of an integer. * 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..ad56131 100644 --- a/src/Iterators/NGrams.php +++ b/src/Iterators/NGrams.php @@ -4,26 +4,16 @@ 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; + private $currentValue; - /** - * NGrams constructor. - * - * @param array $dataset - * The dataset - * @param int $length - * The shift length - */ public function __construct(array $dataset = [], $length = 1) { - parent::__construct($dataset, $length); + $this->shift = new Shift($dataset, $length); $this->currentValue = array_slice( $this->getDataset(), @@ -32,33 +22,30 @@ public function __construct(array $dataset = [], $length = 1) ); } - /** - * {@inheritdoc} - */ + public function getDataset(): array + { + return $this->shift->getDataset(); + } + public function current(): mixed { return $this->currentValue; } - /** - * {@inheritdoc} - * - * @return void - */ public function next(): void { - parent::next(); - $this->currentValue = array_slice($this->current, 0, $this->getLength()); + $this->shift->next(); + $this->currentValue = array_slice($this->current(), 0, $this->getLength()); } - /** - * {@inheritdoc} - * - * @return void - */ public function rewind(): void { - parent::rewind(); - $this->currentValue = array_slice($this->current, 0, $this->getLength()); + $this->shift->rewind(); + $this->currentValue = array_slice($this->current(), 0, $this->getLength()); + } + + 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/src/AbstractTester.php b/tests/src/AbstractTester.php new file mode 100644 index 0000000..9a5fbb2 --- /dev/null +++ b/tests/src/AbstractTester.php @@ -0,0 +1,65 @@ +files()->in($path) as $file) { + $type = basename($file->getRelativePathname(), '.yml'); + $data[$type] = [ + 'file' => $file->getRelativePathname(), + 'type' => basename($file->getRelativePathname(), '.yml'), + 'content' => Yaml::parse($file->getContents()), + ]; + } + } + + return $data; + } +} 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..065b993 100644 --- a/tests/src/Iterators/NgramsTest.php +++ b/tests/src/Iterators/NgramsTest.php @@ -5,29 +5,16 @@ namespace drupol\phpermutations\Tests\Iterators; use drupol\phpermutations\Iterators\NGrams; -use drupol\phpermutations\Tests\AbstractTest; +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)] +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']); 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']);