Skip to content

Commit 165357a

Browse files
author
Six
committed
More CS fixes.
1 parent b9843bb commit 165357a

File tree

6 files changed

+52
-51
lines changed

6 files changed

+52
-51
lines changed

tests/AbstractStrategyTest.php

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Blibio\Combinatorics\Test;
56

67
use Blibio\Combinatorics\AbstractStrategy;
7-
use InvalidArgumentException;
8-
use Override;
98
use 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
*/
1514
final 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
*/
136138
final 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

tests/Combination/WithRepetitionTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Blibio\Combinatorics\Test\Combination;
56

67
use Blibio\Combinatorics\Combinatorics;
7-
use InvalidArgumentException;
88
use PHPUnit\Framework\Attributes\DataProvider;
99
use PHPUnit\Framework\TestCase;
1010

1111
final class WithRepetitionTest extends TestCase
1212
{
1313
public function testThrowsOnEmptyArray(): void
1414
{
15-
$this->expectException(InvalidArgumentException::class);
15+
$this->expectException(\InvalidArgumentException::class);
1616
$this->expectExceptionMessage('Cannot generate combinations/permutations from empty array.');
1717

1818
Combinatorics::combinationsWithRepetition([], 1);
1919
}
2020

2121
public function testThrowsOnNumLessThanZero(): void
2222
{
23-
$this->expectException(InvalidArgumentException::class);
23+
$this->expectException(\InvalidArgumentException::class);
2424
$this->expectExceptionMessage('$k must be greater than zero, got: -1');
2525

2626
/** @phpstan-ignore argument.type */
2727
Combinatorics::combinationsWithRepetition(['A'], -1);
2828
}
2929

3030
/**
31-
* @param list<mixed> $elements
31+
* @param list<mixed> $elements
3232
* @param array<array-key, mixed> $expected
3333
*/
3434
#[DataProvider('results')]
@@ -44,7 +44,7 @@ public function testResults(array $elements, int $k, array $expected): void
4444
}
4545

4646
/**
47-
* @param list<mixed> $elements
47+
* @param list<mixed> $elements
4848
* @param array<array-key, mixed> $expected
4949
*/
5050
#[DataProvider('results')]
@@ -53,7 +53,7 @@ public function testCounts(array $elements, int $k, array $expected): void
5353
/** @phpstan-ignore argument.type */
5454
$uut = Combinatorics::combinationsWithRepetition($elements, $k);
5555

56-
self::assertCount(count($expected), $uut);
56+
self::assertCount(\count($expected), $uut);
5757
}
5858

5959
/** @return array<array-key, mixed> */

tests/Combination/WithoutRepetitionTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Blibio\Combinatorics\Test\Combination;
56

67
use Blibio\Combinatorics\Combinatorics;
7-
use InvalidArgumentException;
88
use PHPUnit\Framework\Attributes\DataProvider;
99
use PHPUnit\Framework\TestCase;
1010

1111
final class WithoutRepetitionTest extends TestCase
1212
{
1313
public function testThrowsOnNumGreaterThanElements(): void
1414
{
15-
$this->expectException(InvalidArgumentException::class);
15+
$this->expectException(\InvalidArgumentException::class);
1616
$this->expectExceptionMessage('$k (2) must not be greater than number of elements (1)');
1717

1818
Combinatorics::combinationsWithoutRepetition(['A'], 2);
1919
}
2020

2121
/**
22-
* @param list<mixed> $elements
22+
* @param list<mixed> $elements
2323
* @param array<array-key, mixed> $expected
2424
*/
2525
#[DataProvider('results')]
@@ -35,7 +35,7 @@ public function testResults(array $elements, int $k, array $expected): void
3535
}
3636

3737
/**
38-
* @param list<mixed> $elements
38+
* @param list<mixed> $elements
3939
* @param array<array-key, mixed> $expected
4040
*/
4141
#[DataProvider('results')]
@@ -44,7 +44,7 @@ public function testCounts(array $elements, int $k, array $expected): void
4444
/** @phpstan-ignore argument.type */
4545
$uut = Combinatorics::combinationsWithoutRepetition($elements, $k);
4646

47-
self::assertCount(count($expected), $uut);
47+
self::assertCount(\count($expected), $uut);
4848
}
4949

5050
/** @return array<array-key, mixed> */
@@ -92,7 +92,7 @@ public static function results(): array
9292
['B', 'C', 'D'],
9393
['B', 'C', 'E'],
9494
['B', 'D', 'E'],
95-
['C', 'D', 'E']
95+
['C', 'D', 'E'],
9696
],
9797
],
9898
];

tests/Permutation/WithRepetitionTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Blibio\Combinatorics\Test\Permutation;
56

67
use Blibio\Combinatorics\Combinatorics;
7-
use Countable;
8-
use InvalidArgumentException;
98
use PHPUnit\Framework\Attributes\DataProvider;
109
use PHPUnit\Framework\TestCase;
11-
use Traversable;
1210

1311
final class WithRepetitionTest extends TestCase
1412
{
1513
public function testThrowsOnEmptyArray(): void
1614
{
17-
$this->expectException(InvalidArgumentException::class);
15+
$this->expectException(\InvalidArgumentException::class);
1816
$this->expectExceptionMessage('Cannot generate combinations/permutations from empty array.');
1917

2018
Combinatorics::permutationsWithRepetition([], 1);
2119
}
2220

2321
public function testThrowsOnNumLessThanZero(): void
2422
{
25-
$this->expectException(InvalidArgumentException::class);
23+
$this->expectException(\InvalidArgumentException::class);
2624
$this->expectExceptionMessage('$k must be greater than zero, got: -1');
2725

2826
/** @phpstan-ignore argument.type */
2927
Combinatorics::permutationsWithRepetition(['A'], -1);
3028
}
3129

3230
/**
33-
* @param list<mixed> $elements
31+
* @param list<mixed> $elements
3432
* @param array<array-key, mixed> $expected
3533
*/
3634
#[DataProvider('results')]
@@ -46,7 +44,7 @@ public function testResults(array $elements, int $k, array $expected): void
4644
}
4745

4846
/**
49-
* @param list<mixed> $elements
47+
* @param list<mixed> $elements
5048
* @param array<array-key, mixed> $expected
5149
*/
5250
#[DataProvider('results')]
@@ -55,7 +53,7 @@ public function testCounts(array $elements, int $k, array $expected): void
5553
/** @phpstan-ignore argument.type */
5654
$uut = Combinatorics::permutationsWithRepetition($elements, $k);
5755

58-
self::assertCount(count($expected), $uut);
56+
self::assertCount(\count($expected), $uut);
5957
}
6058

6159
/** @return array<array-key, mixed> */

tests/Permutation/WithoutRepetitionTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Blibio\Combinatorics\Test\Permutation;
56

67
use Blibio\Combinatorics\Combinatorics;
7-
use InvalidArgumentException;
88
use PHPUnit\Framework\Attributes\DataProvider;
99
use PHPUnit\Framework\TestCase;
1010

1111
final class WithoutRepetitionTest extends TestCase
1212
{
1313
public function testThrowsOnEmptyArray(): void
1414
{
15-
$this->expectException(InvalidArgumentException::class);
15+
$this->expectException(\InvalidArgumentException::class);
1616
$this->expectExceptionMessage('Cannot generate combinations/permutations from empty array.');
1717

1818
Combinatorics::permutationsWithoutRepetition([], 1);
1919
}
2020

2121
public function testThrowsOnNumLessThanZero(): void
2222
{
23-
$this->expectException(InvalidArgumentException::class);
23+
$this->expectException(\InvalidArgumentException::class);
2424
$this->expectExceptionMessage('$k must be greater than zero, got: -1');
2525

2626
/** @phpstan-ignore argument.type */
@@ -29,14 +29,14 @@ public function testThrowsOnNumLessThanZero(): void
2929

3030
public function testThrowsOnNumGreaterThanElements(): void
3131
{
32-
$this->expectException(InvalidArgumentException::class);
32+
$this->expectException(\InvalidArgumentException::class);
3333
$this->expectExceptionMessage('$k (2) must not be greater than number of elements (1)');
3434

3535
Combinatorics::permutationsWithoutRepetition(['A'], 2);
3636
}
3737

3838
/**
39-
* @param list<mixed> $elements
39+
* @param list<mixed> $elements
4040
* @param array<array-key, mixed> $expected
4141
*/
4242
#[DataProvider('results')]
@@ -52,7 +52,7 @@ public function testResults(array $elements, int $k, array $expected): void
5252
}
5353

5454
/**
55-
* @param list<mixed> $elements
55+
* @param list<mixed> $elements
5656
* @param array<array-key, mixed> $expected
5757
*/
5858
#[DataProvider('results')]
@@ -61,7 +61,7 @@ public function testCounts(array $elements, int $k, array $expected): void
6161
/** @phpstan-ignore argument.type */
6262
$uut = Combinatorics::permutationsWithoutRepetition($elements, $k);
6363

64-
self::assertCount(count($expected), $uut);
64+
self::assertCount(\count($expected), $uut);
6565
}
6666

6767
/** @return array<array-key, mixed> */

0 commit comments

Comments
 (0)