diff --git a/composer.json b/composer.json index 692e8cc..449ca9f 100644 --- a/composer.json +++ b/composer.json @@ -23,12 +23,11 @@ "satooshi/php-coveralls": "^1.0", "phpunit/php-code-coverage": "^4.0", "scrutinizer/ocular": "^1.3", - "drupal/coder": "^8.2", "phpro/grumphp": "^0.11" }, "scripts": { - "phpcs": "./vendor/bin/phpcs --standard=vendor/drupal/coder/coder_sniffer/Drupal --ignore=vendor .", - "phpcbf": "./vendor/bin/phpcbf --standard=vendor/drupal/coder/coder_sniffer/Drupal --ignore=vendor .", + "phpcs": "./vendor/bin/phpcs --standard=PSR2 --ignore=vendor .", + "phpcbf": "./vendor/bin/phpcbf --standard=PSR2 --ignore=vendor .", "phpunit": "./vendor/bin/phpunit --coverage-clover build/logs/clover.xml -c tests/phpunit.xml tests", "grumphp": "./vendor/bin/grumphp run", "coveralls": "./vendor/bin/coveralls", diff --git a/grumphp.yml.dist b/grumphp.yml.dist index deda1ab..f389eba 100644 --- a/grumphp.yml.dist +++ b/grumphp.yml.dist @@ -3,7 +3,7 @@ parameters: bin_dir: vendor/bin tasks: phpcs: - standard: vendor/drupal/coder/coder_sniffer/Drupal/ + standard: PSR2 ignore_patterns: - vendor/ triggered_by: diff --git a/src/Combinatorics.php b/src/Combinatorics.php index 6b9d156..6d7fa8d 100644 --- a/src/Combinatorics.php +++ b/src/Combinatorics.php @@ -7,28 +7,29 @@ * * @package drupol\phpermutations */ -abstract class Combinatorics implements \Countable { +abstract class Combinatorics implements \Countable +{ /** * The dataset. * * @var array */ - protected $dataset; + protected $dataset; /** * The number of values in the dataset. * * @var int */ - protected $datasetCount; + protected $datasetCount; /** * The length. * * @var int */ - protected $length; + protected $length; /** * Combinatorics constructor. @@ -38,11 +39,12 @@ abstract class Combinatorics implements \Countable { * @param int|null $length * The length. */ - public function __construct(array $dataset = array(), $length = NULL) { - $this->setDataset($dataset); - $this->datasetCount = count($this->dataset); - $this->setLength($length); - } + public function __construct(array $dataset = array(), $length = null) + { + $this->setDataset($dataset); + $this->datasetCount = count($this->dataset); + $this->setLength($length); + } /** * Set the length. @@ -52,12 +54,13 @@ public function __construct(array $dataset = array(), $length = NULL) { * * @return $this */ - public function setLength($length = NULL) { - $length = is_null($length) ? $this->datasetCount : $length; - $this->length = ($length > $this->datasetCount) ? $this->datasetCount : $length; + public function setLength($length = null) + { + $length = is_null($length) ? $this->datasetCount : $length; + $this->length = ($length > $this->datasetCount) ? $this->datasetCount : $length; - return $this; - } + return $this; + } /** * Get the length. @@ -65,9 +68,10 @@ public function setLength($length = NULL) { * @return int * The length. */ - public function getLength() { - return (int) $this->length; - } + public function getLength() + { + return (int) $this->length; + } /** * Set the dataset. @@ -77,11 +81,12 @@ public function getLength() { * * @return $this */ - public function setDataset(array $dataset = array()) { - $this->dataset = $dataset; + public function setDataset(array $dataset = array()) + { + $this->dataset = $dataset; - return $this; - } + return $this; + } /** * Get the dataset. @@ -89,9 +94,10 @@ public function setDataset(array $dataset = array()) { * @return mixed[] * The dataset. */ - public function getDataset() { - return $this->dataset; - } + public function getDataset() + { + return $this->dataset; + } /** * Compute the factorial of an integer. @@ -104,8 +110,8 @@ public function getDataset() { * @return int * The factorial of $n. */ - protected function fact($n, $total = 1) { - return ($n < 2) ? $total : $this->fact($n - 1, $total * $n); - } - + protected function fact($n, $total = 1) + { + return ($n < 2) ? $total : $this->fact($n - 1, $total * $n); + } } diff --git a/src/Generators/Combinations.php b/src/Generators/Combinations.php index f1e2058..9e83f31 100644 --- a/src/Generators/Combinations.php +++ b/src/Generators/Combinations.php @@ -11,7 +11,8 @@ * * @author Mark Wilson */ -class Combinations extends CombinationsIterator { +class Combinations extends CombinationsIterator +{ /** * Alias of the get() method. @@ -19,9 +20,10 @@ class Combinations extends CombinationsIterator { * @return \Generator * The prime generator. */ - public function generator() { - return $this->get($this->getDataset(), $this->getLength()); - } + public function generator() + { + return $this->get($this->getDataset(), $this->getLength()); + } /** * The generator. @@ -35,23 +37,23 @@ public function generator() { * @return \Generator * @codingStandardsIgnoreEnd */ - protected function get(array $dataset, $length) { - $originalLength = count($dataset); - $remainingLength = $originalLength - $length + 1; - for ($i = 0; $i < $remainingLength; $i++) { - $current = $dataset[$i]; - if ($length === 1) { - yield [$current]; - } - else { - $remaining = array_slice($dataset, $i + 1); - foreach ($this->get($remaining, $length - 1) as $permutation) { - array_unshift($permutation, $current); - yield $permutation; + protected function get(array $dataset, $length) + { + $originalLength = count($dataset); + $remainingLength = $originalLength - $length + 1; + for ($i = 0; $i < $remainingLength; $i++) { + $current = $dataset[$i]; + if ($length === 1) { + yield [$current]; + } else { + $remaining = array_slice($dataset, $i + 1); + foreach ($this->get($remaining, $length - 1) as $permutation) { + array_unshift($permutation, $current); + yield $permutation; + } + } } - } } - } /** * Convert the generator into an array. @@ -59,14 +61,14 @@ protected function get(array $dataset, $length) { * @return array * The elements. */ - public function toArray() { - $data = array(); - - foreach ($this->generator() as $value) { - $data[] = $value; - } + public function toArray() + { + $data = array(); - return $data; - } + foreach ($this->generator() as $value) { + $data[] = $value; + } + return $data; + } } diff --git a/src/Generators/Fibonacci.php b/src/Generators/Fibonacci.php index ba8b3d1..60354b2 100644 --- a/src/Generators/Fibonacci.php +++ b/src/Generators/Fibonacci.php @@ -9,14 +9,15 @@ * * @package drupol\phpermutations\Generators */ -class Fibonacci extends FibonacciIterator { +class Fibonacci extends FibonacciIterator +{ /** * The maximum value. * * @var int */ - protected $max; + protected $max; /** * Alias of the get() method. @@ -24,9 +25,10 @@ class Fibonacci extends FibonacciIterator { * @return \Generator * The prime generator. */ - public function generator() { - return $this->get(); - } + public function generator() + { + return $this->get(); + } /** * The generator. @@ -35,16 +37,16 @@ public function generator() { * @return \Generator * @codingStandardsIgnoreEnd */ - protected function get() { - $a = 0; - $b = 1; - $to = $this->getMaxLimit(); - while ($to > 0) { - yield $a; - - list($a, $b) = array($b, $a + $b); - $to--; + protected function get() + { + $a = 0; + $b = 1; + $to = $this->getMaxLimit(); + while ($to > 0) { + yield $a; + + list($a, $b) = array($b, $a + $b); + $to--; + } } - } - } diff --git a/src/Generators/FiniteGroup.php b/src/Generators/FiniteGroup.php index 7c96538..67103e2 100644 --- a/src/Generators/FiniteGroup.php +++ b/src/Generators/FiniteGroup.php @@ -11,7 +11,8 @@ * * @package drupol\phpermutations\Generators */ -class FiniteGroup extends FiniteGroupIterator { +class FiniteGroup extends FiniteGroupIterator +{ /** * Alias of the get() method. @@ -19,9 +20,10 @@ class FiniteGroup extends FiniteGroupIterator { * @return \Generator * The finite group generator. */ - public function generator() { - return $this->get(); - } + public function generator() + { + return $this->get(); + } /** * The generator. @@ -31,10 +33,10 @@ public function generator() { * The finite group generator. * @codingStandardsIgnoreEnd */ - protected function get() { - foreach ($this->group as $number) { - yield $number; + protected function get() + { + foreach ($this->group as $number) { + yield $number; + } } - } - } diff --git a/src/Generators/Perfect.php b/src/Generators/Perfect.php index b9de628..34e9760 100644 --- a/src/Generators/Perfect.php +++ b/src/Generators/Perfect.php @@ -9,14 +9,15 @@ * * @package drupol\phpermutations\Generators */ -class Perfect extends PerfectIterator { +class Perfect extends PerfectIterator +{ /** * The maximum value. * * @var int */ - protected $max; + protected $max; /** * Alias of the get() method. @@ -24,9 +25,10 @@ class Perfect extends PerfectIterator { * @return \Generator * The prime generator. */ - public function generator() { - return $this->get(); - } + public function generator() + { + return $this->get(); + } /** * The generator. @@ -35,12 +37,12 @@ public function generator() { * @return \Generator * @codingStandardsIgnoreEnd */ - protected function get() { - for ($j = 2; $j <= $this->getMaxLimit(); $j++) { - if ($this->isPerfectNumber($j)) { - yield $j; - } + protected function get() + { + for ($j = 2; $j <= $this->getMaxLimit(); $j++) { + if ($this->isPerfectNumber($j)) { + yield $j; + } + } } - } - } diff --git a/src/Generators/Permutations.php b/src/Generators/Permutations.php index 8233bfb..758a80e 100644 --- a/src/Generators/Permutations.php +++ b/src/Generators/Permutations.php @@ -11,14 +11,15 @@ * * Inspired by the work of Mark Wilson */ -class Permutations extends Combinatorics { +class Permutations extends Combinatorics +{ /** * The combinations generator. * * @var \drupol\phpermutations\Generators\Combinations */ - protected $combinations; + protected $combinations; /** * Combinatorics constructor. @@ -28,10 +29,11 @@ class Permutations extends Combinatorics { * @param int|null $length * The length. */ - public function __construct(array $dataset = array(), $length = NULL) { - parent::__construct($dataset, $length); - $this->combinations = new Combinations($dataset, $this->getLength()); - } + public function __construct(array $dataset = array(), $length = null) + { + parent::__construct($dataset, $length); + $this->combinations = new Combinations($dataset, $this->getLength()); + } /** * Alias of the get() method. @@ -40,13 +42,14 @@ public function __construct(array $dataset = array(), $length = NULL) { * @return \Generator * @codingStandardsIgnoreEnd */ - public function generator() { - foreach ($this->combinations->generator() as $combination) { - foreach ($this->get($combination) as $current) { - yield $current; - } + public function generator() + { + foreach ($this->combinations->generator() as $combination) { + foreach ($this->get($combination) as $current) { + yield $current; + } + } } - } /** * The permutations generator. @@ -58,20 +61,21 @@ public function generator() { * @return \Generator * @codingStandardsIgnoreEnd */ - protected function get(array $dataset) { - foreach ($dataset as $key => $firstItem) { - $remaining = $dataset; - array_splice($remaining, $key, 1); - if (count($remaining) === 0) { - yield [$firstItem]; - continue; - } - foreach ($this->get($remaining) as $permutation) { - array_unshift($permutation, $firstItem); - yield $permutation; - } + protected function get(array $dataset) + { + foreach ($dataset as $key => $firstItem) { + $remaining = $dataset; + array_splice($remaining, $key, 1); + if (count($remaining) === 0) { + yield [$firstItem]; + continue; + } + foreach ($this->get($remaining) as $permutation) { + array_unshift($permutation, $firstItem); + yield $permutation; + } + } } - } /** * Convert the generator into an array. @@ -79,21 +83,22 @@ protected function get(array $dataset) { * @return array * The elements. */ - public function toArray() { - $data = array(); + public function toArray() + { + $data = array(); - foreach ($this->generator() as $value) { - $data[] = $value; - } + foreach ($this->generator() as $value) { + $data[] = $value; + } - return $data; - } + return $data; + } /** * {@inheritdoc} */ - public function count() { - return $this->combinations->count() * $this->fact($this->getLength()); - } - + public function count() + { + return $this->combinations->count() * $this->fact($this->getLength()); + } } diff --git a/src/Generators/Prime.php b/src/Generators/Prime.php index c046b8b..46eadd0 100644 --- a/src/Generators/Prime.php +++ b/src/Generators/Prime.php @@ -9,7 +9,8 @@ * * @package drupol\phpermutations\Generators */ -class Prime extends PrimeIterator { +class Prime extends PrimeIterator +{ /** * Alias of the get() method. @@ -17,9 +18,10 @@ class Prime extends PrimeIterator { * @return \Generator * The prime generator. */ - public function generator() { - return $this->get(); - } + public function generator() + { + return $this->get(); + } /** * The generator. @@ -29,12 +31,12 @@ public function generator() { * The prime generator. * @codingStandardsIgnoreEnd */ - protected function get() { - for ($j = 2; $j <= $this->getMaxLimit(); $j++) { - if ($this->isPrimeNumber($j)) { - yield $j; - } + protected function get() + { + for ($j = 2; $j <= $this->getMaxLimit(); $j++) { + if ($this->isPrimeNumber($j)) { + yield $j; + } + } } - } - } diff --git a/src/Generators/PrimeFactors.php b/src/Generators/PrimeFactors.php index 68edadd..fb7574c 100644 --- a/src/Generators/PrimeFactors.php +++ b/src/Generators/PrimeFactors.php @@ -9,7 +9,8 @@ * * @package drupol\phpermutations\Generators */ -class PrimeFactors extends PrimeFactorsIterator { +class PrimeFactors extends PrimeFactorsIterator +{ /** * Alias of the get() method. @@ -17,9 +18,10 @@ class PrimeFactors extends PrimeFactorsIterator { * @return \Generator * The prime factors generator. */ - public function generator() { - return $this->get(); - } + public function generator() + { + return $this->get(); + } /** * The generator. @@ -29,19 +31,19 @@ public function generator() { * The prime factors generator. * @codingStandardsIgnoreEnd */ - protected function get() { - $number = $this->getNumber(); - - for ($i = 2; $i <= $number / $i; $i++) { - while ($number % $i == 0) { - yield $i; - $number /= $i; - } + protected function get() + { + $number = $this->getNumber(); + + for ($i = 2; $i <= $number / $i; $i++) { + while ($number % $i == 0) { + yield $i; + $number /= $i; + } + } + + if ($number > 1) { + yield $number; + } } - - if ($number > 1) { - yield $number; - } - } - } diff --git a/src/Generators/Product.php b/src/Generators/Product.php index 100e732..0799300 100644 --- a/src/Generators/Product.php +++ b/src/Generators/Product.php @@ -9,7 +9,8 @@ * * @package drupol\phpermutations\Generators */ -class Product extends ProductIterator { +class Product extends ProductIterator +{ /** * Get the generator. @@ -17,9 +18,10 @@ class Product extends ProductIterator { * @return \Generator * The generator. */ - public function generator() { - return $this->get($this->getDataset()); - } + public function generator() + { + return $this->get($this->getDataset()); + } /** * Get the generator. @@ -31,19 +33,18 @@ public function generator() { * The generator. * @codingStandardsIgnoreEnd */ - protected function get(array $data) { - if (!empty($data)) { - if ($u = array_pop($data)) { - foreach ($this->get($data) as $p) { - foreach ($u as $v) { - yield $p + [count($p) => $v]; - } + protected function get(array $data) + { + 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 []; } - } - } - else { - yield []; } - } - } diff --git a/src/Iterators/Combinations.php b/src/Iterators/Combinations.php index 3cb0619..238f476 100644 --- a/src/Iterators/Combinations.php +++ b/src/Iterators/Combinations.php @@ -9,21 +9,22 @@ * * @package drupol\phpermutations\Iterators */ -class Combinations extends Combinatorics implements \Iterator { +class Combinations extends Combinatorics implements \Iterator +{ /** * The values. * * @var array */ - protected $c = array(); + protected $c = array(); /** * The key. * * @var int */ - protected $key = 0; + protected $key = 0; /** * Combinations constructor. @@ -33,55 +34,60 @@ class Combinations extends Combinatorics implements \Iterator { * @param int|null $length * The length. */ - public function __construct(array $dataset = array(), $length = NULL) { - parent::__construct(array_values($dataset), $length); - $this->rewind(); - } + public function __construct(array $dataset = array(), $length = null) + { + parent::__construct(array_values($dataset), $length); + $this->rewind(); + } /** * {@inheritdoc} */ - public function key() { - return $this->key; - } + public function key() + { + return $this->key; + } /** * {@inheritdoc} */ - public function current() { - $r = array(); - for ($i = 0; $i < $this->length; $i++) { - $r[] = $this->dataset[$this->c[$i]]; + public function current() + { + $r = array(); + for ($i = 0; $i < $this->length; $i++) { + $r[] = $this->dataset[$this->c[$i]]; + } + return $r; } - return $r; - } /** * {@inheritdoc} */ - public function next() { - if ($this->nextHelper()) { - $this->key++; - } - else { - $this->key = -1; + public function next() + { + if ($this->nextHelper()) { + $this->key++; + } else { + $this->key = -1; + } } - } /** * {@inheritdoc} */ - public function rewind() { - $this->c = range(0, $this->length); - $this->key = 0; - } + public function rewind() + { + $this->c = range(0, $this->length); + $this->key = 0; + } /** * {@inheritdoc} */ - public function valid() { - return $this->key >= 0; - } + public function valid() + { + return $this->key >= 0; + } /** * Custom next() callback. @@ -89,21 +95,22 @@ public function valid() { * @return bool * Return true or false. */ - protected function nextHelper() { - $i = $this->length - 1; - while ($i >= 0 && $this->c[$i] == $this->datasetCount - $this->length + $i) { - $i--; - } - if ($i < 0) { - return FALSE; + protected function nextHelper() + { + $i = $this->length - 1; + while ($i >= 0 && $this->c[$i] == $this->datasetCount - $this->length + $i) { + $i--; + } + if ($i < 0) { + return false; + } + $this->c[$i]++; + while ($i++ < $this->length - 1) { + $this->c[$i] = $this->c[$i - 1] + 1; + } + + return true; } - $this->c[$i]++; - while ($i++ < $this->length - 1) { - $this->c[$i] = $this->c[$i - 1] + 1; - } - - return TRUE; - } /** * Convert the iterator into an array. @@ -111,21 +118,23 @@ protected function nextHelper() { * @return array * The elements. */ - public function toArray() { - $data = []; + public function toArray() + { + $data = []; - for ($this->rewind(); $this->valid(); $this->next()) { - $data[] = $this->current(); - } + for ($this->rewind(); $this->valid(); $this->next()) { + $data[] = $this->current(); + } - return $data; - } + return $data; + } /** * {@inheritdoc} */ - public function count() { - return $this->fact(count($this->getDataset())) / ($this->fact($this->getLength()) * $this->fact(count($this->getDataset()) - $this->getLength())); - } - + public function count() + { + return $this->fact(count($this->getDataset())) / + ($this->fact($this->getLength()) * $this->fact(count($this->getDataset()) - $this->getLength())); + } } diff --git a/src/Iterators/Cycle.php b/src/Iterators/Cycle.php index 5e06f61..4a1eec0 100644 --- a/src/Iterators/Cycle.php +++ b/src/Iterators/Cycle.php @@ -9,55 +9,61 @@ * * @package drupol\phpermutations\Iterators */ -class Cycle extends Combinatorics implements \Iterator, \Countable { +class Cycle extends Combinatorics implements \Iterator, \Countable +{ /** * The key. * * @var int */ - protected $key = 0; + protected $key = 0; /** * {@inheritdoc} */ - public function key() { - return $this->key; - } + public function key() + { + return $this->key; + } /** * {@inheritdoc} */ - public function current() { - return $this->dataset[$this->key]; - } + public function current() + { + return $this->dataset[$this->key]; + } /** * {@inheritdoc} */ - public function next() { - $this->key = ($this->key + 1) % $this->datasetCount; - } + public function next() + { + $this->key = ($this->key + 1) % $this->datasetCount; + } /** * {@inheritdoc} */ - public function rewind() { - $this->key = 0; - } + public function rewind() + { + $this->key = 0; + } /** * {@inheritdoc} */ - public function valid() { - return TRUE; - } + public function valid() + { + return true; + } /** * {@inheritdoc} */ - public function count() { - return count($this->getDataset()); - } - + public function count() + { + return count($this->getDataset()); + } } diff --git a/src/Iterators/Fibonacci.php b/src/Iterators/Fibonacci.php index d18dc48..e20304f 100644 --- a/src/Iterators/Fibonacci.php +++ b/src/Iterators/Fibonacci.php @@ -9,87 +9,95 @@ * * @package drupol\phpermutations\Iterators */ -class Fibonacci extends Combinatorics implements \Iterator, \Countable { +class Fibonacci extends Combinatorics implements \Iterator, \Countable +{ /** * The maximum limit. * * @var int */ - protected $max; + protected $max; /** * The previous element. * * @var int */ - private $previous = 1; + private $previous = 1; /** * The current element. * * @var int */ - private $current = 0; + private $current = 0; /** * The current key. * * @var int */ - private $key = 0; + private $key = 0; /** * Fibonacci constructor. */ - public function __construct() { - $this->setMaxLimit(PHP_INT_MAX); - } + public function __construct() + { + $this->setMaxLimit(PHP_INT_MAX); + } /** * {@inheritdoc} */ - public function current() { - return $this->current; - } + public function current() + { + return $this->current; + } /** * {@inheritdoc} */ - public function key() { - return $this->key; - } + public function key() + { + return $this->key; + } /** * {@inheritdoc} */ - public function next() { - list($this->current, $this->previous) = array($this->current + $this->previous, $this->current); - $this->key++; - } + public function next() + { + list($this->current, $this->previous) = array($this->current + $this->previous, $this->current); + $this->key++; + } /** * {@inheritdoc} */ - public function rewind() { - $this->previous = 1; - $this->current = 0; - $this->key = 0; - } + public function rewind() + { + $this->previous = 1; + $this->current = 0; + $this->key = 0; + } /** * {@inheritdoc} */ - public function valid() { - return ($this->current < $this->getMaxLimit()); - } + public function valid() + { + return ($this->current < $this->getMaxLimit()); + } /** * {@inheritdoc} */ - public function count() { - return count($this->toArray()); - } + public function count() + { + return count($this->toArray()); + } /** * Convert the iterator into an array. @@ -97,15 +105,16 @@ public function count() { * @return array * The elements. */ - public function toArray() { - $data = array(); + public function toArray() + { + $data = array(); - for ($this->rewind(); $this->valid(); $this->next()) { - $data[] = $this->current(); - } + for ($this->rewind(); $this->valid(); $this->next()) { + $data[] = $this->current(); + } - return $data; - } + return $data; + } /** * Set the maximum limit. @@ -113,9 +122,10 @@ public function toArray() { * @param int $max * The limit. */ - public function setMaxLimit($max) { - $this->max = $max; - } + public function setMaxLimit($max) + { + $this->max = $max; + } /** * Get the maximum limit. @@ -123,8 +133,8 @@ public function setMaxLimit($max) { * @return int * The limit. */ - public function getMaxLimit() { - return intval($this->max); - } - + public function getMaxLimit() + { + return intval($this->max); + } } diff --git a/src/Iterators/FiniteGroup.php b/src/Iterators/FiniteGroup.php index beaa1d3..17421ba 100644 --- a/src/Iterators/FiniteGroup.php +++ b/src/Iterators/FiniteGroup.php @@ -11,71 +11,78 @@ * * @package drupol\phpermutations\Iterators */ -class FiniteGroup extends Combinatorics implements \Iterator, \Countable { +class FiniteGroup extends Combinatorics implements \Iterator, \Countable +{ /** * The group size. * * @var int */ - protected $size; + protected $size; /** * The group. * * @var int[] */ - protected $group; + protected $group; /** * The key. * * @var int */ - protected $key; + protected $key; /** * Combinatorics constructor. */ - public function __construct() { - parent::__construct(array(), NULL); - } + public function __construct() + { + parent::__construct(array(), null); + } /** * {@inheritdoc} */ - public function current() { - return current($this->group); - } + public function current() + { + return current($this->group); + } /** * {@inheritdoc} */ - public function next() { - $this->key++; - next($this->group); - } + public function next() + { + $this->key++; + next($this->group); + } /** * {@inheritdoc} */ - public function key() { - return $this->key; - } + public function key() + { + return $this->key; + } /** * {@inheritdoc} */ - public function valid() { - return isset($this->group[$this->key()]); - } + public function valid() + { + return isset($this->group[$this->key()]); + } /** * {@inheritdoc} */ - public function rewind() { - $this->key = 0; - } + public function rewind() + { + $this->key = 0; + } /** * Count elements of an object. @@ -83,9 +90,10 @@ public function rewind() { * @return int * The number of element. */ - public function count() { - return count($this->group); - } + public function count() + { + return count($this->group); + } /** * Convert the iterator into an array. @@ -93,15 +101,16 @@ public function count() { * @return array * The elements. */ - public function toArray() { - $data = array(); + public function toArray() + { + $data = array(); - for ($this->rewind(); $this->valid(); $this->next()) { - $data[] = $this->current(); - } + for ($this->rewind(); $this->valid(); $this->next()) { + $data[] = $this->current(); + } - return $data; - } + return $data; + } /** * Set the group size. @@ -109,10 +118,11 @@ public function toArray() { * @param int $size * The size. */ - public function setSize($size) { - $this->size = $size; - $this->computeGroup(); - } + public function setSize($size) + { + $this->size = $size; + $this->computeGroup(); + } /** * Get the group size. @@ -120,22 +130,24 @@ public function setSize($size) { * @return int * The size. */ - public function getSize() { - return intval($this->size); - } + public function getSize() + { + return intval($this->size); + } /** * Clean out the group from unwanted values. */ - private function computeGroup() { - $this->group = array(); + private function computeGroup() + { + $this->group = array(); - foreach (range(1, $this->getSize() - 1) as $number) { - if ($this->gcd($number, $this->getSize() - 1) == 1) { - $this->group[] = $number; - } + foreach (range(1, $this->getSize() - 1) as $number) { + if ($this->gcd($number, $this->getSize() - 1) == 1) { + $this->group[] = $number; + } + } } - } /** * Get the greater common divisor between two numbers. @@ -148,9 +160,10 @@ private function computeGroup() { * @return int * The greater common divisor between $a and $b. */ - private function gcd($a, $b) { - return $b ? $this->gcd($b, $a % $b) : $a; - } + private function gcd($a, $b) + { + return $b ? $this->gcd($b, $a % $b) : $a; + } /** * Get the order. @@ -161,15 +174,15 @@ private function gcd($a, $b) { * @return int * The order. */ - public function order($generator) { - $result = array(); + public function order($generator) + { + $result = array(); - foreach (range(1, $this->getSize() - 1) as $number) { - $value = pow($generator, $number) % $this->getSize(); - $result[$value] = $value; - } - - return count($result); - } + foreach (range(1, $this->getSize() - 1) as $number) { + $value = pow($generator, $number) % $this->getSize(); + $result[$value] = $value; + } + return count($result); + } } diff --git a/src/Iterators/Perfect.php b/src/Iterators/Perfect.php index 032ef56..c481a74 100644 --- a/src/Iterators/Perfect.php +++ b/src/Iterators/Perfect.php @@ -9,78 +9,85 @@ * * @package drupol\phpermutations\Iterators */ -class Perfect extends Combinatorics implements \Iterator, \Countable { +class Perfect extends Combinatorics implements \Iterator, \Countable +{ /** * The minimum limit. * * @var int */ - protected $min; + protected $min; /** * The maximum limit. * * @var int */ - protected $max; + protected $max; /** * The key. * * @var int */ - protected $key; + protected $key; /** * Perfect constructor. */ - public function __construct() { - $this->setMaxLimit(PHP_INT_MAX); - $this->setMinLimit(2); - } + public function __construct() + { + $this->setMaxLimit(PHP_INT_MAX); + $this->setMinLimit(2); + } /** * {@inheritdoc} */ - public function current() { - for ($i = $this->key(); $i < $this->getMaxLimit(); $i++) { - if ($this->isPerfectNumber($i)) { - $this->key = $i; - return $i; - } - } + public function current() + { + for ($i = $this->key(); $i < $this->getMaxLimit(); $i++) { + if ($this->isPerfectNumber($i)) { + $this->key = $i; + return $i; + } + } - return $this->getMaxLimit(); - } + return $this->getMaxLimit(); + } /** * {@inheritdoc} */ - public function next() { - $this->key++; - } + public function next() + { + $this->key++; + } /** * {@inheritdoc} */ - public function key() { - return $this->key; - } + public function key() + { + return $this->key; + } /** * {@inheritdoc} */ - public function valid() { - return $this->current() < $this->getMaxLimit(); - } + public function valid() + { + return $this->current() < $this->getMaxLimit(); + } /** * {@inheritdoc} */ - public function rewind() { - $this->key = $this->getMinLimit(); - } + public function rewind() + { + $this->key = $this->getMinLimit(); + } /** * Count elements of an object. @@ -88,9 +95,10 @@ public function rewind() { * @return int * The number of element. */ - public function count() { - return count($this->toArray()); - } + public function count() + { + return count($this->toArray()); + } /** * Convert the iterator into an array. @@ -98,15 +106,16 @@ public function count() { * @return array * The elements. */ - public function toArray() { - $data = array(); + public function toArray() + { + $data = array(); - for ($this->rewind(); $this->valid(); $this->next()) { - $data[] = $this->current(); - } + for ($this->rewind(); $this->valid(); $this->next()) { + $data[] = $this->current(); + } - return $data; - } + return $data; + } /** * Test if a number is perfect or not. @@ -119,20 +128,21 @@ public function toArray() { * @return bool * The true if the number is perfect, false otherwise. */ - protected function isPerfectNumber($number) { - $d = 0; - $max = sqrt($number); - for ($n = 2; $n <= $max; $n++) { - if (!($number % $n)) { - $d += $n; - if ($n <> $number / $n) { - $d += $number / $n; + protected function isPerfectNumber($number) + { + $d = 0; + $max = sqrt($number); + for ($n = 2; $n <= $max; $n++) { + if (!($number % $n)) { + $d += $n; + if ($n <> $number / $n) { + $d += $number / $n; + } + } } - } - } - return ++$d == $number; - } + return ++$d == $number; + } /** * Set the maximum limit. @@ -140,9 +150,10 @@ protected function isPerfectNumber($number) { * @param int $max * The limit. */ - public function setMaxLimit($max) { - $this->max = $max; - } + public function setMaxLimit($max) + { + $this->max = $max; + } /** * Get the maximum limit. @@ -150,9 +161,10 @@ public function setMaxLimit($max) { * @return int * The limit. */ - public function getMaxLimit() { - return intval($this->max); - } + public function getMaxLimit() + { + return intval($this->max); + } /** * Set the minimum limit. @@ -160,9 +172,10 @@ public function getMaxLimit() { * @param int $min * The limit. */ - public function setMinLimit($min) { - $this->min = $min; - } + public function setMinLimit($min) + { + $this->min = $min; + } /** * Get the minimum limit. @@ -170,8 +183,8 @@ public function setMinLimit($min) { * @return int * The limit. */ - public function getMinLimit() { - return $this->min < 2 ? 2 : $this->min; - } - + public function getMinLimit() + { + return $this->min < 2 ? 2 : $this->min; + } } diff --git a/src/Iterators/Prime.php b/src/Iterators/Prime.php index f95ced8..c8bbdcb 100644 --- a/src/Iterators/Prime.php +++ b/src/Iterators/Prime.php @@ -9,78 +9,85 @@ * * @package drupol\phpermutations\Iterators */ -class Prime extends Combinatorics implements \Iterator, \Countable { +class Prime extends Combinatorics implements \Iterator, \Countable +{ /** * The minimum limit. * * @var int */ - protected $min; + protected $min; /** * The maximum limit. * * @var int */ - protected $max; + protected $max; /** * The key. * * @var int */ - protected $key; + protected $key; /** * Prime constructor. */ - public function __construct() { - $this->setMaxLimit(PHP_INT_MAX); - $this->setMinLimit(0); - } + public function __construct() + { + $this->setMaxLimit(PHP_INT_MAX); + $this->setMinLimit(0); + } /** * {@inheritdoc} */ - public function current() { - for ($i = $this->key(); $i < $this->getMaxLimit(); $i++) { - if ($this->isPrimeNumber($i)) { - $this->key = $i; - return $i; - } - } + public function current() + { + for ($i = $this->key(); $i < $this->getMaxLimit(); $i++) { + if ($this->isPrimeNumber($i)) { + $this->key = $i; + return $i; + } + } - return $this->getMaxLimit(); - } + return $this->getMaxLimit(); + } /** * {@inheritdoc} */ - public function next() { - $this->key++; - } + public function next() + { + $this->key++; + } /** * {@inheritdoc} */ - public function key() { - return $this->key; - } + public function key() + { + return $this->key; + } /** * {@inheritdoc} */ - public function valid() { - return $this->current() < $this->getMaxLimit(); - } + public function valid() + { + return $this->current() < $this->getMaxLimit(); + } /** * {@inheritdoc} */ - public function rewind() { - $this->key = $this->getMinLimit(); - } + public function rewind() + { + $this->key = $this->getMinLimit(); + } /** * Count elements of an object. @@ -88,9 +95,10 @@ public function rewind() { * @return int * The number of element. */ - public function count() { - return count($this->toArray()); - } + public function count() + { + return count($this->toArray()); + } /** * Convert the iterator into an array. @@ -98,15 +106,16 @@ public function count() { * @return array * The elements. */ - public function toArray() { - $data = array(); + public function toArray() + { + $data = array(); - for ($this->rewind(); $this->valid(); $this->next()) { - $data[] = $this->current(); - } + for ($this->rewind(); $this->valid(); $this->next()) { + $data[] = $this->current(); + } - return $data; - } + return $data; + } /** * Test if a number is prime or not. @@ -117,28 +126,29 @@ public function toArray() { * @return bool * The true if the number is prime, false otherwise. */ - protected function isPrimeNumber($number) { - $number = abs($number); + protected function isPrimeNumber($number) + { + $number = abs($number); - // 2 is an exception. - if (2 == $number) { - return TRUE; - } + // 2 is an exception. + if (2 == $number) { + return true; + } - // Check if number is even. - if (!($number & 1)) { - return FALSE; - } + // Check if number is even. + if (!($number & 1)) { + return false; + } - $sqrtNumber = sqrt($number); - for ($divisor = 3; $divisor <= $sqrtNumber; $divisor += 2) { - if ($number % $divisor == 0) { - return FALSE; - } - } + $sqrtNumber = sqrt($number); + for ($divisor = 3; $divisor <= $sqrtNumber; $divisor += 2) { + if ($number % $divisor == 0) { + return false; + } + } - return TRUE; - } + return true; + } /** * Set the maximum limit. @@ -146,9 +156,10 @@ protected function isPrimeNumber($number) { * @param int $max * The limit. */ - public function setMaxLimit($max) { - $this->max = $max; - } + public function setMaxLimit($max) + { + $this->max = $max; + } /** * Get the maximum limit. @@ -156,9 +167,10 @@ public function setMaxLimit($max) { * @return int * The limit. */ - public function getMaxLimit() { - return intval($this->max); - } + public function getMaxLimit() + { + return intval($this->max); + } /** * Set the minimum limit. @@ -166,9 +178,10 @@ public function getMaxLimit() { * @param int $min * The limit. */ - public function setMinLimit($min) { - $this->min = $min; - } + public function setMinLimit($min) + { + $this->min = $min; + } /** * Get the minimum limit. @@ -176,8 +189,8 @@ public function setMinLimit($min) { * @return int * The limit. */ - public function getMinLimit() { - return $this->min <= 2 ? 2 : intval($this->min); - } - + public function getMinLimit() + { + return $this->min <= 2 ? 2 : intval($this->min); + } } diff --git a/src/Iterators/PrimeFactors.php b/src/Iterators/PrimeFactors.php index bdf0685..4a31443 100644 --- a/src/Iterators/PrimeFactors.php +++ b/src/Iterators/PrimeFactors.php @@ -9,64 +9,70 @@ * * @package drupol\phpermutations\Iterators */ -class PrimeFactors extends Combinatorics implements \Iterator, \Countable { +class PrimeFactors extends Combinatorics implements \Iterator, \Countable +{ /** * The number. * * @var int */ - protected $number; + protected $number; /** * The key. * * @var int */ - protected $key; + protected $key; /** * The prime factors. * * @var int[] */ - protected $factors; + protected $factors; /** * {@inheritdoc} */ - public function current() { - return current($this->factors); - } + public function current() + { + return current($this->factors); + } /** * {@inheritdoc} */ - public function next() { - $this->key++; - next($this->factors); - } + public function next() + { + $this->key++; + next($this->factors); + } /** * {@inheritdoc} */ - public function key() { - return $this->key; - } + public function key() + { + return $this->key; + } /** * {@inheritdoc} */ - public function valid() { - return isset($this->factors[$this->key()]); - } + public function valid() + { + return isset($this->factors[$this->key()]); + } /** * {@inheritdoc} */ - public function rewind() { - $this->key = 0; - } + public function rewind() + { + $this->key = 0; + } /** * Count elements of an object. @@ -74,9 +80,10 @@ public function rewind() { * @return int * The number of element. */ - public function count() { - return count($this->factors); - } + public function count() + { + return count($this->factors); + } /** * Convert the iterator into an array. @@ -84,15 +91,16 @@ public function count() { * @return array * The elements. */ - public function toArray() { - $data = array(); + public function toArray() + { + $data = array(); - for ($this->rewind(); $this->valid(); $this->next()) { - $data[] = $this->current(); - } + for ($this->rewind(); $this->valid(); $this->next()) { + $data[] = $this->current(); + } - return $data; - } + return $data; + } /** * Set the number. @@ -100,10 +108,11 @@ public function toArray() { * @param int $number * The number. */ - public function setNumber($number) { - $this->number = $number; - $this->factors = $this->getFactors($this->getNumber()); - } + public function setNumber($number) + { + $this->number = $number; + $this->factors = $this->getFactors($this->getNumber()); + } /** * Get the number. @@ -111,9 +120,10 @@ public function setNumber($number) { * @return int * The number. */ - public function getNumber() { - return intval($this->number); - } + public function getNumber() + { + return intval($this->number); + } /** * Compute the prime factors of the number. @@ -121,23 +131,23 @@ public function getNumber() { * @return int[] * The factors. */ - private function getFactors($number) { - if ($number <= 0) { - $factors = array(); - } - - for ($i = 2; $i <= $number / $i; $i++) { - while ($number % $i == 0) { - $factors[] = $i; - $number /= $i; - } + private function getFactors($number) + { + if ($number <= 0) { + $factors = array(); + } + + for ($i = 2; $i <= $number / $i; $i++) { + while ($number % $i == 0) { + $factors[] = $i; + $number /= $i; + } + } + + if ($number > 1) { + $factors[] = $number; + } + + return $factors; } - - if ($number > 1) { - $factors[] = $number; - } - - return $factors; - } - } diff --git a/src/Iterators/Product.php b/src/Iterators/Product.php index 7ad50a1..532c54c 100644 --- a/src/Iterators/Product.php +++ b/src/Iterators/Product.php @@ -9,21 +9,22 @@ * * @package drupol\phpermutations\Iterators */ -class Product extends Combinatorics implements \Iterator, \Countable { +class Product extends Combinatorics implements \Iterator, \Countable +{ /** * The key. * * @var int */ - protected $key; + protected $key; /** * The iterators. * * @var \Iterator[] */ - protected $iterators = array(); + protected $iterators = array(); /** * Product constructor. @@ -31,95 +32,101 @@ class Product extends Combinatorics implements \Iterator, \Countable { * @param array $datasetArray * The array of dataset. */ - public function __construct(array $datasetArray) { - parent::__construct($datasetArray); + public function __construct(array $datasetArray) + { + parent::__construct($datasetArray); - foreach ($datasetArray as $dataset) { - $this->iterators[] = new \ArrayIterator($dataset); - } + foreach ($datasetArray as $dataset) { + $this->iterators[] = new \ArrayIterator($dataset); + } - $this->key = 0; - } + $this->key = 0; + } /** * {@inheritdoc} */ - public function current() { - $tuple = array(); + public function current() + { + $tuple = array(); - foreach ($this->iterators as $iterator) { - $tuple[] = $iterator->current(); - } + foreach ($this->iterators as $iterator) { + $tuple[] = $iterator->current(); + } - return $tuple; - } + return $tuple; + } /** * {@inheritdoc} */ - public function next() { - $reverseIterators = array_reverse($this->iterators); - - foreach ($reverseIterators as $key => $iterator) { - $iterator->next(); - if ($iterator->valid()) { - foreach ($this->iterators as $key2 => $iterator2) { - if ($key >= count($this->iterators) - $key2) { - $iterator2->rewind(); - } + public function next() + { + foreach (array_reverse($this->iterators) as $key => $iterator) { + $iterator->next(); + if ($iterator->valid()) { + $count_iterators = count($this->iterators); + foreach ($this->iterators as $key2 => $iterator2) { + if ($key >= $count_iterators - $key2) { + $iterator2->rewind(); + } + } + break; + } } - break; - } - } - $this->key++; - } + $this->key++; + } /** * {@inheritdoc} */ - public function key() { - return $this->key; - } + public function key() + { + return $this->key; + } /** * {@inheritdoc} */ - public function valid() { - $isUnlessOneValid = FALSE; + public function valid() + { + $isUnlessOneValid = false; + + foreach ($this->iterators as $iterator) { + if ($iterator->valid()) { + $isUnlessOneValid = true; + } + } - foreach ($this->iterators as $iterator) { - if ($iterator->valid()) { - $isUnlessOneValid = TRUE; - } + return $isUnlessOneValid; } - return $isUnlessOneValid; - } - /** * {@inheritdoc} */ - public function rewind() { - foreach ($this->iterators as $iterator) { - $iterator->rewind(); - } + public function rewind() + { + foreach ($this->iterators as $iterator) { + $iterator->rewind(); + } - $this->key = 0; - } + $this->key = 0; + } /** * {@inheritdoc} */ - public function count() { - $product = 1; + public function count() + { + $product = 1; - foreach ($this->getDataset() as $dataset) { - $product *= count($dataset); - } + foreach ($this->getDataset() as $dataset) { + $product *= count($dataset); + } - return $product; - } + return $product; + } /** * Convert the iterator into an array. @@ -127,14 +134,14 @@ public function count() { * @return array * The elements. */ - public function toArray() { - $data = array(); - - for ($this->rewind(); $this->valid(); $this->next()) { - $data[] = $this->current(); - } + public function toArray() + { + $data = array(); - return $data; - } + for ($this->rewind(); $this->valid(); $this->next()) { + $data[] = $this->current(); + } + return $data; + } } diff --git a/src/Iterators/Rotation.php b/src/Iterators/Rotation.php index 8523665..924d70a 100644 --- a/src/Iterators/Rotation.php +++ b/src/Iterators/Rotation.php @@ -9,21 +9,22 @@ * * @package drupol\phpermutations\Iterators */ -class Rotation extends Combinatorics implements \Iterator, \Countable { +class Rotation extends Combinatorics implements \Iterator, \Countable +{ /** * The key. * * @var int */ - protected $key = 0; + protected $key = 0; /** * A copy of the original data. * * @var mixed[] */ - protected $rotation; + protected $rotation; /** * Rotation constructor. @@ -31,24 +32,27 @@ class Rotation extends Combinatorics implements \Iterator, \Countable { * @param array $dataset * The dataset. */ - public function __construct(array $dataset = array()) { - parent::__construct($dataset, NULL); - $this->rotation = $this->getDataset(); - } + public function __construct(array $dataset = array()) + { + parent::__construct($dataset, null); + $this->rotation = $this->getDataset(); + } /** * {@inheritdoc} */ - public function key() { - return $this->key; - } + public function key() + { + return $this->key; + } /** * {@inheritdoc} */ - public function current() { - return $this->rotation; - } + public function current() + { + return $this->rotation; + } /** * Compute the next value of the Iterator. @@ -56,30 +60,33 @@ public function current() { * @param int $offset * The offset. */ - public function next($offset = 1) { - $offset = is_null($offset) ? 1 : $offset % $this->count(); - $this->rotation = array_merge(array_slice($this->rotation, $offset), array_slice($this->rotation, 0, $offset)); - } + public function next($offset = 1) + { + $offset = is_null($offset) ? 1 : $offset % $this->count(); + $this->rotation = array_merge(array_slice($this->rotation, $offset), array_slice($this->rotation, 0, $offset)); + } /** * {@inheritdoc} */ - public function rewind() { - $this->rotation = $this->getDataset(); - } + public function rewind() + { + $this->rotation = $this->getDataset(); + } /** * {@inheritdoc} */ - public function valid() { - return TRUE; - } + public function valid() + { + return true; + } /** * {@inheritdoc} */ - public function count() { - return count($this->getDataset()); - } - + public function count() + { + return count($this->getDataset()); + } } diff --git a/tests/src/AbstractTest.php b/tests/src/AbstractTest.php index 4ed602f..d22eb19 100644 --- a/tests/src/AbstractTest.php +++ b/tests/src/AbstractTest.php @@ -11,12 +11,13 @@ * * @package drupol\phpermutations\Tests */ -abstract class AbstractTest extends TestCase { +abstract class AbstractTest extends TestCase +{ /** * The type. */ - const TYPE = NULL; + const TYPE = null; /** * The data provider. @@ -24,13 +25,14 @@ abstract class AbstractTest extends TestCase { * @return array * The test input values and their expected output. */ - public function dataProvider() { - $fixtures = $this->fixtureProvider(); - if ($this::TYPE !== NULL && $fixtures[$this::TYPE]['content']) { - return $fixtures[$this::TYPE]['content']; + public function dataProvider() + { + $fixtures = $this->fixtureProvider(); + if ($this::TYPE !== null && $fixtures[$this::TYPE]['content']) { + return $fixtures[$this::TYPE]['content']; + } + return array(); } - return array(); - } /** * Return component fixtures. @@ -38,20 +40,20 @@ public function dataProvider() { * @return array * List of component fixtures. */ - public function fixtureProvider() { - $data = []; - - $finder = new Finder(); - $finder->files()->in(realpath(__DIR__ . '/../fixtures')); - foreach ($finder as $file) { - $type = basename($file->getRelativePathname(), '.yml'); - $data[$type] = [ - 'file' => $file->getRelativePathname(), - 'type' => basename($file->getRelativePathname(), '.yml'), - 'content' => Yaml::parse($file->getContents()), - ]; + public function fixtureProvider() + { + $data = []; + + $finder = new Finder(); + $finder->files()->in(realpath(__DIR__ . '/../fixtures')); + foreach ($finder as $file) { + $type = basename($file->getRelativePathname(), '.yml'); + $data[$type] = [ + 'file' => $file->getRelativePathname(), + 'type' => basename($file->getRelativePathname(), '.yml'), + 'content' => Yaml::parse($file->getContents()), + ]; + } + return $data; } - return $data; - } - } diff --git a/tests/src/Generators/CombinationsTest.php b/tests/src/Generators/CombinationsTest.php index 23fa3eb..a40127c 100644 --- a/tests/src/Generators/CombinationsTest.php +++ b/tests/src/Generators/CombinationsTest.php @@ -10,25 +10,33 @@ * * @package drupol\phpermutations\Tests */ -class CombinationsTest extends AbstractTest { +class CombinationsTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'combinations'; + const TYPE = 'combinations'; /** * The tests. * * @dataProvider dataProvider */ - public function testCombinationsClass($input, $expected) { - $combinations = new Combinations($input['dataset'], $input['length']); - - $this->assertEquals($input['dataset'], $combinations->getDataset()); - $this->assertEquals($input['length'], $combinations->getLength()); - $this->assertEquals($expected['dataset'], $combinations->toArray(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = TRUE); - $this->assertEquals($expected['count'], $combinations->count()); - } + public function testCombinationsClass($input, $expected) + { + $combinations = new Combinations($input['dataset'], $input['length']); + $this->assertEquals($input['dataset'], $combinations->getDataset()); + $this->assertEquals($input['length'], $combinations->getLength()); + $this->assertEquals( + $expected['dataset'], + $combinations->toArray(), + "\$canonicalize = true", + $delta = 0.0, + $maxDepth = 10, + $canonicalize = true + ); + $this->assertEquals($expected['count'], $combinations->count()); + } } diff --git a/tests/src/Generators/FibonacciTest.php b/tests/src/Generators/FibonacciTest.php index 180385a..e76fdc7 100644 --- a/tests/src/Generators/FibonacciTest.php +++ b/tests/src/Generators/FibonacciTest.php @@ -10,24 +10,32 @@ * * @package drupol\phpermutations\Tests\Generators */ -class FibonacciTest extends AbstractTest { +class FibonacciTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'fibonacci'; + const TYPE = 'fibonacci'; /** * The tests. * * @dataProvider dataProvider */ - public function testFibonacci($input, $expected) { - $prime = new Fibonacci(); - $prime->setMaxLimit(1000); - - $this->assertEquals($expected['count'], $prime->count()); - $this->assertEquals($expected['dataset'], $prime->toArray(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = TRUE); - } + public function testFibonacci($input, $expected) + { + $prime = new Fibonacci(); + $prime->setMaxLimit(1000); + $this->assertEquals($expected['count'], $prime->count()); + $this->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 index 4262e4c..00c19d1 100644 --- a/tests/src/Generators/FiniteGroupTest.php +++ b/tests/src/Generators/FiniteGroupTest.php @@ -10,24 +10,32 @@ * * @package drupol\phpermutations\Tests\Generators */ -class FiniteGroupTest extends AbstractTest { +class FiniteGroupTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'finitegroup'; + const TYPE = 'finitegroup'; /** * The tests. * * @dataProvider dataProvider */ - public function testFiniteGroup($input, $expected) { - $prime = new FiniteGroup(); - $prime->setSize($input['size']); - - $this->assertEquals($expected['count'], $prime->count()); - $this->assertEquals($expected['dataset'], $prime->toArray(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = TRUE); - } + public function testFiniteGroup($input, $expected) + { + $prime = new FiniteGroup(); + $prime->setSize($input['size']); + $this->assertEquals($expected['count'], $prime->count()); + $this->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 index 6521946..5417c78 100644 --- a/tests/src/Generators/PerfectTest.php +++ b/tests/src/Generators/PerfectTest.php @@ -10,32 +10,39 @@ * * @package drupol\phpermutations\Tests\Generators */ -class PerfectTest extends AbstractTest { +class PerfectTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'perfect'; + const TYPE = 'perfect'; /** * The tests. * * @dataProvider dataProvider */ - public function testPerfect($input, $expected) { - $perfect = new Perfect(); - $perfect->setMinLimit($input['min']); - $perfect->setMaxLimit($input['max']); + public function testPerfect($input, $expected) + { + $perfect = new Perfect(); + $perfect->setMinLimit($input['min']); + $perfect->setMaxLimit($input['max']); - if ($input['min'] < 2) { - $this->assertEquals(2, $perfect->getMinLimit()); + if ($input['min'] < 2) { + $this->assertEquals(2, $perfect->getMinLimit()); + } else { + $this->assertEquals($input['min'], $perfect->getMinLimit()); + } + $this->assertEquals($input['max'], $perfect->getMaxLimit()); + $this->assertEquals($expected['count'], $perfect->count()); + $this->assertEquals( + $expected['dataset'], + $perfect->toArray(), + "\$canonicalize = true", + $delta = 0.0, + $maxDepth = 10, + $canonicalize = true + ); } - else { - $this->assertEquals($input['min'], $perfect->getMinLimit()); - } - $this->assertEquals($input['max'], $perfect->getMaxLimit()); - $this->assertEquals($expected['count'], $perfect->count()); - $this->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 index 52d43f5..653cbe7 100644 --- a/tests/src/Generators/PermutationsTest.php +++ b/tests/src/Generators/PermutationsTest.php @@ -10,12 +10,13 @@ * * @package drupol\phpermutations\Tests\Generators */ -class PermutationsTest extends AbstractTest { +class PermutationsTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'permutations'; + const TYPE = 'permutations'; /** * Test. @@ -23,13 +24,20 @@ class PermutationsTest extends AbstractTest { * @dataProvider dataProvider * The data provider */ - public function testPermutations($input, $expected) { - $generator = new Permutations($input['dataset'], $input['length']); - - $this->assertEquals($input['dataset'], $generator->getDataset()); - $this->assertEquals($input['length'], $generator->getLength()); - $this->assertEquals($expected['count'], $generator->count()); - $this->assertEquals($expected['dataset'], $generator->toArray(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = TRUE); - } + public function testPermutations($input, $expected) + { + $generator = new Permutations($input['dataset'], $input['length']); + $this->assertEquals($input['dataset'], $generator->getDataset()); + $this->assertEquals($input['length'], $generator->getLength()); + $this->assertEquals($expected['count'], $generator->count()); + $this->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 index f277df1..3e5543a 100644 --- a/tests/src/Generators/PrimeFactorsTest.php +++ b/tests/src/Generators/PrimeFactorsTest.php @@ -10,24 +10,32 @@ * * @package drupol\phpermutations\Tests\Generators */ -class PrimeFactorsTest extends AbstractTest { +class PrimeFactorsTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'primefactors'; + const TYPE = 'primefactors'; /** * The tests. * * @dataProvider dataProvider */ - public function testPrimeFactors($input, $expected) { - $prime = new PrimeFactors(); - $prime->setNumber($input['number']); - - $this->assertEquals($expected['count'], $prime->count()); - $this->assertEquals($expected['dataset'], $prime->toArray(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = TRUE); - } + public function testPrimeFactors($input, $expected) + { + $prime = new PrimeFactors(); + $prime->setNumber($input['number']); + $this->assertEquals($expected['count'], $prime->count()); + $this->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 index 555c09f..7fc5001 100644 --- a/tests/src/Generators/PrimeTest.php +++ b/tests/src/Generators/PrimeTest.php @@ -10,33 +10,40 @@ * * @package drupol\phpermutations\Tests\Generators */ -class PrimeTest extends AbstractTest { +class PrimeTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'prime'; + const TYPE = 'prime'; /** * The tests. * * @dataProvider dataProvider */ - public function testPrime($input, $expected) { - $prime = new Prime(); - $prime->setMinLimit($input['min']); - $prime->setMaxLimit($input['max']); - - if ($input['min'] < 2) { - $this->assertEquals(2, $prime->getMinLimit()); - } - else { - $this->assertEquals($input['min'], $prime->getMinLimit()); + public function testPrime($input, $expected) + { + $prime = new Prime(); + $prime->setMinLimit($input['min']); + $prime->setMaxLimit($input['max']); + + if ($input['min'] < 2) { + $this->assertEquals(2, $prime->getMinLimit()); + } else { + $this->assertEquals($input['min'], $prime->getMinLimit()); + } + $this->assertEquals($input['max'], $prime->getMaxLimit()); + + $this->assertEquals($expected['count'], $prime->count()); + $this->assertEquals( + $expected['dataset'], + $prime->toArray(), + "\$canonicalize = true", + $delta = 0.0, + $maxDepth = 10, + $canonicalize = true + ); } - $this->assertEquals($input['max'], $prime->getMaxLimit()); - - $this->assertEquals($expected['count'], $prime->count()); - $this->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 index da05d0f..f48fe7c 100644 --- a/tests/src/Generators/ProductTest.php +++ b/tests/src/Generators/ProductTest.php @@ -10,24 +10,32 @@ * * @package drupol\phpermutations\Tests\Generators */ -class ProductTest extends AbstractTest { +class ProductTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'product'; + const TYPE = 'product'; /** * The tests. * * @dataProvider dataProvider */ - public function testProduct($input, $expected) { - $product = new Product($input['dataset']); - - $this->assertEquals($input['dataset'], $product->getDataset()); - $this->assertEquals($expected['count'], $product->count()); - $this->assertEquals($expected['dataset'], $product->toArray(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = TRUE); - } + public function testProduct($input, $expected) + { + $product = new Product($input['dataset']); + $this->assertEquals($input['dataset'], $product->getDataset()); + $this->assertEquals($expected['count'], $product->count()); + $this->assertEquals( + $expected['dataset'], + $product->toArray(), + "\$canonicalize = true", + $delta = 0.0, + $maxDepth = 10, + $canonicalize = true + ); + } } diff --git a/tests/src/Iterators/CombinationsTest.php b/tests/src/Iterators/CombinationsTest.php index 7942162..21f72cb 100644 --- a/tests/src/Iterators/CombinationsTest.php +++ b/tests/src/Iterators/CombinationsTest.php @@ -10,26 +10,34 @@ * * @package drupol\phpermutations\Tests\Iterators */ -class CombinationsTest extends AbstractTest { +class CombinationsTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'combinations'; + const TYPE = 'combinations'; /** * The tests. * * @dataProvider dataProvider */ - public function testCombinations($input, $expected) { - $combinations = new Combinations($input['dataset'], $input['length']); - - $this->assertEquals($input['dataset'], $combinations->getDataset()); - $this->assertEquals($input['length'], $combinations->getLength()); - $this->assertEquals(count($input['dataset']), count($combinations->getDataset())); - $this->assertEquals($expected['dataset'], $combinations->toArray(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = TRUE); - $this->assertEquals($expected['count'], $combinations->count()); - } + public function testCombinations($input, $expected) + { + $combinations = new Combinations($input['dataset'], $input['length']); + $this->assertEquals($input['dataset'], $combinations->getDataset()); + $this->assertEquals($input['length'], $combinations->getLength()); + $this->assertEquals(count($input['dataset']), count($combinations->getDataset())); + $this->assertEquals( + $expected['dataset'], + $combinations->toArray(), + "\$canonicalize = true", + $delta = 0.0, + $maxDepth = 10, + $canonicalize = true + ); + $this->assertEquals($expected['count'], $combinations->count()); + } } diff --git a/tests/src/Iterators/CycleTest.php b/tests/src/Iterators/CycleTest.php index 1e4a14a..7cab434 100644 --- a/tests/src/Iterators/CycleTest.php +++ b/tests/src/Iterators/CycleTest.php @@ -10,28 +10,29 @@ * * @package drupol\phpermutations\Tests\Iterators */ -class CycleTest extends AbstractTest { +class CycleTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'cycle'; + const TYPE = 'cycle'; /** * The tests. * * @dataProvider dataProvider */ - public function testCycle($input, $expected) { - $cycle = new Cycle($input['dataset']); + public function testCycle($input, $expected) + { + $cycle = new Cycle($input['dataset']); - for ($i = 0; $i < $input['turn']; $i++) { - $cycle->next(); - } - $this->assertEquals($expected['current'], $cycle->current()); - - $this->assertEquals($input['dataset'], $cycle->getDataset()); - $this->assertEquals($expected['count'], $cycle->count()); - } + for ($i = 0; $i < $input['turn']; $i++) { + $cycle->next(); + } + $this->assertEquals($expected['current'], $cycle->current()); + $this->assertEquals($input['dataset'], $cycle->getDataset()); + $this->assertEquals($expected['count'], $cycle->count()); + } } diff --git a/tests/src/Iterators/FibonacciTest.php b/tests/src/Iterators/FibonacciTest.php index 3fbab15..144a4f9 100644 --- a/tests/src/Iterators/FibonacciTest.php +++ b/tests/src/Iterators/FibonacciTest.php @@ -10,24 +10,32 @@ * * @package drupol\phpermutations\Tests\Iterators */ -class FibonacciTest extends AbstractTest { +class FibonacciTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'fibonacci'; + const TYPE = 'fibonacci'; /** * The tests. * * @dataProvider dataProvider */ - public function testFibonacci($input, $expected) { - $prime = new Fibonacci(); - $prime->setMaxLimit(1000); - - $this->assertEquals($expected['count'], $prime->count()); - $this->assertEquals($expected['dataset'], $prime->toArray(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = TRUE); - } + public function testFibonacci($input, $expected) + { + $prime = new Fibonacci(); + $prime->setMaxLimit(1000); + $this->assertEquals($expected['count'], $prime->count()); + $this->assertEquals( + $expected['dataset'], + $prime->toArray(), + "\$canonicalize = true", + $delta = 0.0, + $maxDepth = 10, + $canonicalize = true + ); + } } diff --git a/tests/src/Iterators/FiniteGroupTest.php b/tests/src/Iterators/FiniteGroupTest.php index d57a486..5d8ae52 100644 --- a/tests/src/Iterators/FiniteGroupTest.php +++ b/tests/src/Iterators/FiniteGroupTest.php @@ -10,24 +10,32 @@ * * @package drupol\phpermutations\Tests\Iterators */ -class FiniteGroupTest extends AbstractTest { +class FiniteGroupTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'finitegroup'; + const TYPE = 'finitegroup'; /** * The tests. * * @dataProvider dataProvider */ - public function testFiniteGroup($input, $expected) { - $prime = new FiniteGroup(); - $prime->setSize($input['size']); - - $this->assertEquals($expected['count'], $prime->count()); - $this->assertEquals($expected['dataset'], $prime->toArray(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = TRUE); - } + public function testFiniteGroup($input, $expected) + { + $prime = new FiniteGroup(); + $prime->setSize($input['size']); + $this->assertEquals($expected['count'], $prime->count()); + $this->assertEquals( + $expected['dataset'], + $prime->toArray(), + "\$canonicalize = true", + $delta = 0.0, + $maxDepth = 10, + $canonicalize = true + ); + } } diff --git a/tests/src/Iterators/PerfectTest.php b/tests/src/Iterators/PerfectTest.php index 4655117..7fa26a8 100644 --- a/tests/src/Iterators/PerfectTest.php +++ b/tests/src/Iterators/PerfectTest.php @@ -10,33 +10,40 @@ * * @package drupol\phpermutations\Tests\Iterators */ -class PerfectTest extends AbstractTest { +class PerfectTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'perfect'; + const TYPE = 'perfect'; /** * The tests. * * @dataProvider dataProvider */ - public function testPerfect($input, $expected) { - $perfect = new Perfect(); - $perfect->setMinLimit($input['min']); - $perfect->setMaxLimit($input['max']); + public function testPerfect($input, $expected) + { + $perfect = new Perfect(); + $perfect->setMinLimit($input['min']); + $perfect->setMaxLimit($input['max']); - if ($input['min'] < 2) { - $this->assertEquals(2, $perfect->getMinLimit()); + if ($input['min'] < 2) { + $this->assertEquals(2, $perfect->getMinLimit()); + } else { + $this->assertEquals($input['min'], $perfect->getMinLimit()); + } + $this->assertEquals($input['max'], $perfect->getMaxLimit()); + $this->assertEquals($input['max'], $perfect->getMaxLimit()); + $this->assertEquals($expected['count'], $perfect->count()); + $this->assertEquals( + $expected['dataset'], + $perfect->toArray(), + "\$canonicalize = true", + $delta = 0.0, + $maxDepth = 10, + $canonicalize = true + ); } - else { - $this->assertEquals($input['min'], $perfect->getMinLimit()); - } - $this->assertEquals($input['max'], $perfect->getMaxLimit()); - $this->assertEquals($input['max'], $perfect->getMaxLimit()); - $this->assertEquals($expected['count'], $perfect->count()); - $this->assertEquals($expected['dataset'], $perfect->toArray(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = TRUE); - } - } diff --git a/tests/src/Iterators/PrimeFactorsTest.php b/tests/src/Iterators/PrimeFactorsTest.php index 1c5e90e..b6b07da 100644 --- a/tests/src/Iterators/PrimeFactorsTest.php +++ b/tests/src/Iterators/PrimeFactorsTest.php @@ -10,24 +10,32 @@ * * @package drupol\phpermutations\Tests\Iterators */ -class PrimeFactorsTest extends AbstractTest { +class PrimeFactorsTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'primefactors'; + const TYPE = 'primefactors'; /** * The tests. * * @dataProvider dataProvider */ - public function testPrimeFactors($input, $expected) { - $prime = new PrimeFactors(); - $prime->setNumber($input['number']); - - $this->assertEquals($expected['count'], $prime->count()); - $this->assertEquals($expected['dataset'], $prime->toArray(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = TRUE); - } + public function testPrimeFactors($input, $expected) + { + $prime = new PrimeFactors(); + $prime->setNumber($input['number']); + $this->assertEquals($expected['count'], $prime->count()); + $this->assertEquals( + $expected['dataset'], + $prime->toArray(), + "\$canonicalize = true", + $delta = 0.0, + $maxDepth = 10, + $canonicalize = true + ); + } } diff --git a/tests/src/Iterators/PrimeTest.php b/tests/src/Iterators/PrimeTest.php index 1942d00..8639781 100644 --- a/tests/src/Iterators/PrimeTest.php +++ b/tests/src/Iterators/PrimeTest.php @@ -10,32 +10,39 @@ * * @package drupol\phpermutations\Tests\Iterators */ -class PrimeTest extends AbstractTest { +class PrimeTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'prime'; + const TYPE = 'prime'; /** * The tests. * * @dataProvider dataProvider */ - public function testPrime($input, $expected) { - $prime = new Prime(); - $prime->setMinLimit($input['min']); - $prime->setMaxLimit($input['max']); + public function testPrime($input, $expected) + { + $prime = new Prime(); + $prime->setMinLimit($input['min']); + $prime->setMaxLimit($input['max']); - if ($input['min'] < 2) { - $this->assertEquals(2, $prime->getMinLimit()); + if ($input['min'] < 2) { + $this->assertEquals(2, $prime->getMinLimit()); + } else { + $this->assertEquals($input['min'], $prime->getMinLimit()); + } + $this->assertEquals($input['max'], $prime->getMaxLimit()); + $this->assertEquals($expected['count'], $prime->count()); + $this->assertEquals( + $expected['dataset'], + $prime->toArray(), + "\$canonicalize = true", + $delta = 0.0, + $maxDepth = 10, + $canonicalize = true + ); } - else { - $this->assertEquals($input['min'], $prime->getMinLimit()); - } - $this->assertEquals($input['max'], $prime->getMaxLimit()); - $this->assertEquals($expected['count'], $prime->count()); - $this->assertEquals($expected['dataset'], $prime->toArray(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = TRUE); - } - } diff --git a/tests/src/Iterators/ProductTest.php b/tests/src/Iterators/ProductTest.php index acf000f..82f7cdd 100644 --- a/tests/src/Iterators/ProductTest.php +++ b/tests/src/Iterators/ProductTest.php @@ -10,24 +10,32 @@ * * @package drupol\phpermutations\Tests\Iterators */ -class ProductTest extends AbstractTest { +class ProductTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'product'; + const TYPE = 'product'; /** * The tests. * * @dataProvider dataProvider */ - public function testProduct($input, $expected) { - $product = new Product($input['dataset']); - - $this->assertEquals($input['dataset'], $product->getDataset()); - $this->assertEquals($expected['dataset'], $product->toArray(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = TRUE); - $this->assertEquals($expected['count'], $product->count()); - } + public function testProduct($input, $expected) + { + $product = new Product($input['dataset']); + $this->assertEquals($input['dataset'], $product->getDataset()); + $this->assertEquals( + $expected['dataset'], + $product->toArray(), + "\$canonicalize = true", + $delta = 0.0, + $maxDepth = 10, + $canonicalize = true + ); + $this->assertEquals($expected['count'], $product->count()); + } } diff --git a/tests/src/Iterators/RotationTest.php b/tests/src/Iterators/RotationTest.php index 7ef3600..8f8da48 100644 --- a/tests/src/Iterators/RotationTest.php +++ b/tests/src/Iterators/RotationTest.php @@ -10,30 +10,31 @@ * * @package drupol\phpermutations\Tests\Iterators */ -class RotationTest extends AbstractTest { +class RotationTest extends AbstractTest +{ /** * The type. */ - const TYPE = 'rotation'; + const TYPE = 'rotation'; /** * The tests. * * @dataProvider dataProvider */ - public function testRotation($input, $expected) { - $rotation = new Rotation($input['dataset']); - - $input += array( - 'turn' => NULL, - ); - $rotation->next($input['turn']); - $this->assertSame($expected['dataset'], $rotation->current()); - - $rotation->rewind(); - $this->assertSame($input['dataset'], $rotation->current()); - $this->assertEquals(count($input['dataset']), $rotation->count()); - } - + public function testRotation($input, $expected) + { + $rotation = new Rotation($input['dataset']); + + $input += array( + 'turn' => null, + ); + $rotation->next($input['turn']); + $this->assertSame($expected['dataset'], $rotation->current()); + + $rotation->rewind(); + $this->assertSame($input['dataset'], $rotation->current()); + $this->assertEquals(count($input['dataset']), $rotation->count()); + } }