|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Blibio\Combinatorics\Test; |
| 6 | + |
| 7 | +use Blibio\Combinatorics\Combination; |
| 8 | +use Blibio\Combinatorics\Combinatorics; |
| 9 | +use Blibio\Combinatorics\Permutation; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | + |
| 12 | +final class CombinatoricsTest extends TestCase |
| 13 | +{ |
| 14 | + public function testCombinationsWithRepetitionFromFlag(): void |
| 15 | + { |
| 16 | + $elements = ['A', 'B']; |
| 17 | + $k = 2; |
| 18 | + |
| 19 | + $result = Combinatorics::combinations($elements, $k, withRepetition: true); |
| 20 | + $expected = Combinatorics::combinationsWithRepetition($elements, $k); |
| 21 | + |
| 22 | + self::assertEquals(iterator_to_array($expected), iterator_to_array($result)); |
| 23 | + self::assertInstanceOf(Combination\WithRepetition::class, $result); |
| 24 | + } |
| 25 | + |
| 26 | + public function testCombinationsWithoutRepetitionFromFlag(): void |
| 27 | + { |
| 28 | + $elements = ['A', 'B', 'C']; |
| 29 | + $k = 2; |
| 30 | + |
| 31 | + $result = Combinatorics::combinations($elements, $k, withRepetition: false); |
| 32 | + $expected = Combinatorics::combinationsWithoutRepetition($elements, $k); |
| 33 | + |
| 34 | + self::assertEquals(iterator_to_array($expected), iterator_to_array($result)); |
| 35 | + self::assertInstanceOf(Combination\WithoutRepetition::class, $result); |
| 36 | + } |
| 37 | + |
| 38 | + public function testPermutationsWithRepetitionFromFlag(): void |
| 39 | + { |
| 40 | + $elements = ['A', 'B']; |
| 41 | + $k = 2; |
| 42 | + |
| 43 | + $result = Combinatorics::permutations($elements, $k, withRepetition: true); |
| 44 | + $expected = Combinatorics::permutationsWithRepetition($elements, $k); |
| 45 | + |
| 46 | + self::assertEquals(iterator_to_array($expected), iterator_to_array($result)); |
| 47 | + self::assertInstanceOf(Permutation\WithRepetition::class, $result); |
| 48 | + } |
| 49 | + |
| 50 | + public function testPermutationsWithoutRepetitionFromFlag(): void |
| 51 | + { |
| 52 | + $elements = ['A', 'B', 'C']; |
| 53 | + $k = 2; |
| 54 | + |
| 55 | + $result = Combinatorics::permutations($elements, $k, withRepetition: false); |
| 56 | + $expected = Combinatorics::permutationsWithoutRepetition($elements, $k); |
| 57 | + |
| 58 | + self::assertEquals(iterator_to_array($expected), iterator_to_array($result)); |
| 59 | + self::assertInstanceOf(Permutation\WithoutRepetition::class, $result); |
| 60 | + } |
| 61 | +} |
0 commit comments