11<?php
2+
23declare (strict_types=1 );
34
45namespace Blibio \Combinatorics \Test ;
56
67use Blibio \Combinatorics \AbstractStrategy ;
7- use InvalidArgumentException ;
8- use Override ;
98use PHPUnit \Framework \TestCase ;
109
1110/**
1211 * Tests for AbstractStrategy algorithmic and behavioral concerns
13- * These tests apply to all concrete strategy implementations
12+ * These tests apply to all concrete strategy implementations.
1413 */
1514final class AbstractStrategyTest extends TestCase
1615{
1716 /**
1817 * @template U
18+ *
1919 * @param array<array-key, U> $elements
20- * @param int<1, max> $k
20+ * @param int<1, max> $k
21+ *
2122 * @return TestableStrategy<U>
2223 */
2324 private function createTestableStrategy (array $ elements , int $ k ): TestableStrategy
@@ -28,18 +29,18 @@ private function createTestableStrategy(array $elements, int $k): TestableStrate
2829 public function testGenerateProducesExpectedResults (): void
2930 {
3031 $ strategy = $ this ->createTestableStrategy (['A ' , 'B ' , 'C ' ], 2 );
31-
32+
3233 $ results = [];
3334 foreach ($ strategy as $ combo ) {
3435 $ results [] = $ combo ;
3536 }
36-
37+
3738 $ expected = [
3839 ['A ' , 'B ' ],
39- ['A ' , 'C ' ],
40+ ['A ' , 'C ' ],
4041 ['B ' , 'C ' ],
4142 ];
42-
43+
4344 self ::assertEquals ($ expected , $ results );
4445 self ::assertCount (3 , $ results );
4546 }
@@ -48,15 +49,15 @@ public function testGenerateProducesExpectedResults(): void
4849
4950 public function testThrowsOnEmptyArray (): void
5051 {
51- $ this ->expectException (InvalidArgumentException::class);
52+ $ this ->expectException (\ InvalidArgumentException::class);
5253 $ this ->expectExceptionMessage ('Cannot generate combinations/permutations from empty array. ' );
5354
5455 $ this ->createTestableStrategy ([], 1 );
5556 }
5657
5758 public function testThrowsOnNumLessThanZero (): void
5859 {
59- $ this ->expectException (InvalidArgumentException::class);
60+ $ this ->expectException (\ InvalidArgumentException::class);
6061 $ this ->expectExceptionMessage ('$k must be greater than zero, got: -1 ' );
6162
6263 /** @phpstan-ignore argument.type */
@@ -68,19 +69,19 @@ public function testThrowsOnNumLessThanZero(): void
6869 public function testIteratorReusability (): void
6970 {
7071 $ strategy = $ this ->createTestableStrategy (['A ' , 'B ' ], 1 );
71-
72+
7273 // First iteration
7374 $ firstPass = [];
7475 foreach ($ strategy as $ combo ) {
7576 $ firstPass [] = $ combo ;
7677 }
77-
78+
7879 // Second iteration on iterator
7980 $ secondPass = [];
8081 foreach ($ strategy as $ combo ) {
8182 $ secondPass [] = $ combo ;
8283 }
83-
84+
8485 self ::assertEquals ($ firstPass , $ secondPass );
8586 self ::assertEquals ([['A ' ], ['B ' ]], $ firstPass );
8687 }
@@ -89,37 +90,37 @@ public function testDuplicateElementsAreTreatedAsDistinct(): void
8990 {
9091 // Each array position is treated as a distinct identity
9192 $ strategy = $ this ->createTestableStrategy (['A ' , 'A ' , 'B ' ], 2 );
92-
93+
9394 $ results = [];
9495 foreach ($ strategy as $ combo ) {
9596 $ results [] = $ combo ;
9697 }
97-
98+
9899 // Should get 3 combinations: first-A+second-A, first-A+B, second-A+B
99100 $ expected = [
100101 ['A ' , 'A ' ], // position 0 + position 1
101102 ['A ' , 'B ' ], // position 0 + position 2
102103 ['A ' , 'B ' ], // position 1 + position 2
103104 ];
104-
105+
105106 self ::assertEquals ($ expected , $ results );
106107 self ::assertCount (3 , $ results );
107108 }
108109
109110 public function testIteratorToArrayPreservesAllResults (): void
110111 {
111112 $ strategy = $ this ->createTestableStrategy (['A ' , 'B ' , 'C ' ], 2 );
112-
113+
113114 // Using iterator_to_array with preserve_keys = true should preserve all results
114115 $ arrayResults = iterator_to_array ($ strategy , true );
115-
116+
116117 // Expected: 3 combinations
117118 $ expected = [
118119 ['A ' , 'B ' ],
119- ['A ' , 'C ' ],
120+ ['A ' , 'C ' ],
120121 ['B ' , 'C ' ],
121122 ];
122-
123+
123124 // This should have all 3 results, not just the last one
124125 self ::assertCount (3 , $ arrayResults );
125126 self ::assertEquals ($ expected , array_values ($ arrayResults ));
@@ -131,17 +132,18 @@ public function testIteratorToArrayPreservesAllResults(): void
131132 * Uses basic "combination without repetition" logic for simplicity.
132133 *
133134 * @template T
135+ *
134136 * @extends AbstractStrategy<T>
135137 */
136138final readonly class TestableStrategy extends AbstractStrategy
137139{
138- #[Override]
140+ #[\ Override]
139141 protected function next (array $ elements , int $ i ): array
140142 {
141- return array_slice ($ elements , $ i + 1 );
143+ return \ array_slice ($ elements , $ i + 1 );
142144 }
143145
144- #[Override]
146+ #[\ Override]
145147 public function count (): int
146148 {
147149 // Simple combination formula for testing
0 commit comments