Skip to content

Commit 17b1c10

Browse files
authored
Merge pull request #2 from jspeedz/dev
tests: add some more test assertions and cases
2 parents 77d13c5 + fa1c890 commit 17b1c10

File tree

7 files changed

+756
-84
lines changed

7 files changed

+756
-84
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
branches: [ "main" ]
55
pull_request:
66
branches: [ "main" ]
7+
permissions:
8+
pull-requests: write
79
jobs:
810
build:
911
runs-on: ubuntu-latest
@@ -31,12 +33,12 @@ jobs:
3133
dependency-versions: "${{ matrix.dependencies }}"
3234
composer-options: "${{ matrix.composer-options }}"
3335

34-
- name: Run tests
35-
run: composer test
36-
3736
- name: PHPStan static analysis
3837
run: composer phpstan
3938

39+
- name: Run tests
40+
run: composer test
41+
4042
- name: Code Coverage Report
4143
uses: irongut/[email protected]
4244
with:
@@ -48,7 +50,7 @@ jobs:
4850
hide_complexity: true
4951
indicators: true
5052
output: both
51-
thresholds: '60 80'
53+
thresholds: '50 80'
5254

5355
- name: Add Coverage PR Comment
5456
uses: marocchino/sticky-pull-request-comment@v2

benchmarking/benchmark.php

Lines changed: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,81 @@
4949
'node2' => 30,
5050
'node3' => 50,
5151
],
52-
'33 33 34' => [
53-
'node1' => 33,
54-
'node2' => 33,
55-
'node3' => 34,
52+
'25 25 25 25' => [
53+
'node1' => 100/4,
54+
'node2' => 100/4,
55+
'node3' => 100/4,
56+
'node4' => 100/4,
57+
],
58+
'20 20 20 20 20' => [
59+
'node1' => 100/5,
60+
'node2' => 100/5,
61+
'node3' => 100/5,
62+
'node4' => 100/5,
63+
'node5' => 100/5,
64+
],
65+
'16.6 16.6 16.6 16.6 16.6 16.6' => [
66+
'node1' => 100/6,
67+
'node2' => 100/6,
68+
'node3' => 100/6,
69+
'node4' => 100/6,
70+
'node5' => 100/6,
71+
'node6' => 100/6,
72+
],
73+
'14.2857 14.2857 14.2857 14.2857 14.2857 14.2857 14.2857' => [
74+
'node1' => 100/7,
75+
'node2' => 100/7,
76+
'node3' => 100/7,
77+
'node4' => 100/7,
78+
'node5' => 100/7,
79+
'node6' => 100/7,
80+
'node7' => 100/7,
81+
],
82+
'12.5 12.5 12.5 12.5 12.5 12.5 12.5 12.5' => [
83+
'node1' => 100/8,
84+
'node2' => 100/8,
85+
'node3' => 100/8,
86+
'node4' => 100/8,
87+
'node5' => 100/8,
88+
'node6' => 100/8,
89+
'node7' => 100/8,
90+
'node8' => 100/8,
91+
],
92+
'11.1 11.1 11.1 11.1 11.1 11.1 11.1 11.1 11.1 11.1' => [
93+
'node1' => 100/9,
94+
'node2' => 100/9,
95+
'node3' => 100/9,
96+
'node4' => 100/9,
97+
'node5' => 100/9,
98+
'node6' => 100/9,
99+
'node7' => 100/9,
100+
'node8' => 100/9,
101+
'node9' => 100/9,
102+
],
103+
'10 10 10 10 10 10 10 10 10 10' => [
104+
'node1' => 100/10,
105+
'node2' => 100/10,
106+
'node3' => 100/10,
107+
'node4' => 100/10,
108+
'node5' => 100/10,
109+
'node6' => 100/10,
110+
'node7' => 100/10,
111+
'node8' => 100/10,
112+
'node9' => 100/10,
113+
'node10' => 100/10,
114+
],
115+
'11 11 11 11 11 11 11 11 11 11 11' => [
116+
'node1' => 100/11,
117+
'node2' => 100/11,
118+
'node3' => 100/11,
119+
'node4' => 100/11,
120+
'node5' => 100/11,
121+
'node6' => 100/11,
122+
'node7' => 100/11,
123+
'node8' => 100/11,
124+
'node9' => 100/11,
125+
'node10' => 100/11,
126+
'node11' => 100/11,
56127
],
57128
'15 15 25 45' => [
58129
'node1' => 15,
@@ -67,13 +138,6 @@
67138
'node4' => 5,
68139
'node5' => 5,
69140
],
70-
'20 20 20 20 20' => [
71-
'node1' => 20,
72-
'node2' => 20,
73-
'node3' => 20,
74-
'node4' => 20,
75-
'node5' => 20,
76-
],
77141
'1 1' => [
78142
'node1' => 1,
79143
'node2' => 1,
@@ -279,7 +343,7 @@
279343
SORT_ASC,
280344
);
281345

282-
$benchmark->printResults($results);
346+
echo $benchmark->printResults($results);
283347

284348
if($fp !== false) {
285349
fclose($fp);

phpstan.neon

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ parameters:
22
level: 9
33
paths:
44
- src
5-
- tests
5+
- tests
6+
ignoreErrors:
7+
-
8+
message: '#Variable \$oneHundredAndTwentyNodes in isset\(\) always exists and is always null#'
9+
path: tests/MultiProbeConsistentHashTest.php

src/Benchmark.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
use DateTimeImmutable;
66
use Exception;
77

8-
/**
9-
* @codeCoverageIgnore
10-
* @todo Write tests..
11-
*/
128
class Benchmark {
139
/**
1410
* @param string[] $algorithms
@@ -32,6 +28,7 @@ public function getAvailableHashCallbacks(?array $algorithms = null): array {
3228
}
3329

3430
/**
31+
* @codeCoverageIgnore
3532
* @return string[]
3633
* @throws Exception
3734
*/
@@ -130,6 +127,9 @@ public function sortByTwoColumns(
130127
array_multisort($primaryValues, $primaryDirection, $secondaryValues, $secondaryDirection, $array);
131128
}
132129

130+
/**
131+
* @codeCoverageIgnore
132+
*/
133133
public function printProgress(int $iterationCount, int $totalIterations, DateTimeImmutable $startTime): void {
134134
if($iterationCount % 5 !== 0) {
135135
return;
@@ -142,6 +142,9 @@ public function printProgress(int $iterationCount, int $totalIterations, DateTim
142142
->format('%H:%I:%S') . PHP_EOL;
143143
}
144144

145+
/**
146+
* @codeCoverageIgnore
147+
*/
145148
public function generateData(int $dataCount): void {
146149
$targetDir = __DIR__ . '/../tmp/benchmark/';
147150

@@ -171,8 +174,9 @@ protected function formatNumber(int|float $number): string {
171174
/**
172175
* @param array<int, array<string, string|float>> $results
173176
*/
174-
public function printResults(array $results): void {
175-
echo 'Results:' . PHP_EOL;
177+
public function printResults(array $results): string {
178+
$string = 'Results:' . PHP_EOL;
179+
176180
foreach($results as $result) {
177181
$result['name'] = str_pad((string) $result['name'], 5, ' ', STR_PAD_RIGHT);
178182
$result['distribution'] = str_pad((string) $result['distribution'], 5, ' ', STR_PAD_RIGHT);
@@ -182,15 +186,17 @@ public function printResults(array $results): void {
182186

183187
foreach($result as $title => $value) {
184188
if(in_array($title, ['name', 'distribution'], true)) {
185-
echo '[' . $value . ']';
189+
$string .= '[' . $value . ']';
186190
if($title === 'name') {
187-
echo ' -- ';
191+
$string .= ' -- ';
188192
}
189193
continue;
190194
}
191-
echo $title . ': ' . $value . ' -- ';
195+
$string .= $title . ': ' . $value . ' -- ';
192196
}
193-
echo PHP_EOL;
197+
$string .= PHP_EOL;
194198
}
199+
200+
return $string;
195201
}
196202
}

0 commit comments

Comments
 (0)