Skip to content

Commit

Permalink
Merge pull request #2 from jspeedz/dev
Browse files Browse the repository at this point in the history
tests: add some more test assertions and cases
  • Loading branch information
jspeedz authored Jul 10, 2024
2 parents 77d13c5 + fa1c890 commit 17b1c10
Show file tree
Hide file tree
Showing 7 changed files with 756 additions and 84 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
pull-requests: write
jobs:
build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -31,12 +33,12 @@ jobs:
dependency-versions: "${{ matrix.dependencies }}"
composer-options: "${{ matrix.composer-options }}"

- name: Run tests
run: composer test

- name: PHPStan static analysis
run: composer phpstan

- name: Run tests
run: composer test

- name: Code Coverage Report
uses: irongut/[email protected]
with:
Expand All @@ -48,7 +50,7 @@ jobs:
hide_complexity: true
indicators: true
output: both
thresholds: '60 80'
thresholds: '50 80'

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
Expand Down
88 changes: 76 additions & 12 deletions benchmarking/benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,81 @@
'node2' => 30,
'node3' => 50,
],
'33 33 34' => [
'node1' => 33,
'node2' => 33,
'node3' => 34,
'25 25 25 25' => [
'node1' => 100/4,
'node2' => 100/4,
'node3' => 100/4,
'node4' => 100/4,
],
'20 20 20 20 20' => [
'node1' => 100/5,
'node2' => 100/5,
'node3' => 100/5,
'node4' => 100/5,
'node5' => 100/5,
],
'16.6 16.6 16.6 16.6 16.6 16.6' => [
'node1' => 100/6,
'node2' => 100/6,
'node3' => 100/6,
'node4' => 100/6,
'node5' => 100/6,
'node6' => 100/6,
],
'14.2857 14.2857 14.2857 14.2857 14.2857 14.2857 14.2857' => [
'node1' => 100/7,
'node2' => 100/7,
'node3' => 100/7,
'node4' => 100/7,
'node5' => 100/7,
'node6' => 100/7,
'node7' => 100/7,
],
'12.5 12.5 12.5 12.5 12.5 12.5 12.5 12.5' => [
'node1' => 100/8,
'node2' => 100/8,
'node3' => 100/8,
'node4' => 100/8,
'node5' => 100/8,
'node6' => 100/8,
'node7' => 100/8,
'node8' => 100/8,
],
'11.1 11.1 11.1 11.1 11.1 11.1 11.1 11.1 11.1 11.1' => [
'node1' => 100/9,
'node2' => 100/9,
'node3' => 100/9,
'node4' => 100/9,
'node5' => 100/9,
'node6' => 100/9,
'node7' => 100/9,
'node8' => 100/9,
'node9' => 100/9,
],
'10 10 10 10 10 10 10 10 10 10' => [
'node1' => 100/10,
'node2' => 100/10,
'node3' => 100/10,
'node4' => 100/10,
'node5' => 100/10,
'node6' => 100/10,
'node7' => 100/10,
'node8' => 100/10,
'node9' => 100/10,
'node10' => 100/10,
],
'11 11 11 11 11 11 11 11 11 11 11' => [
'node1' => 100/11,
'node2' => 100/11,
'node3' => 100/11,
'node4' => 100/11,
'node5' => 100/11,
'node6' => 100/11,
'node7' => 100/11,
'node8' => 100/11,
'node9' => 100/11,
'node10' => 100/11,
'node11' => 100/11,
],
'15 15 25 45' => [
'node1' => 15,
Expand All @@ -67,13 +138,6 @@
'node4' => 5,
'node5' => 5,
],
'20 20 20 20 20' => [
'node1' => 20,
'node2' => 20,
'node3' => 20,
'node4' => 20,
'node5' => 20,
],
'1 1' => [
'node1' => 1,
'node2' => 1,
Expand Down Expand Up @@ -279,7 +343,7 @@
SORT_ASC,
);

$benchmark->printResults($results);
echo $benchmark->printResults($results);

if($fp !== false) {
fclose($fp);
Expand Down
6 changes: 5 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ parameters:
level: 9
paths:
- src
- tests
- tests
ignoreErrors:
-
message: '#Variable \$oneHundredAndTwentyNodes in isset\(\) always exists and is always null#'
path: tests/MultiProbeConsistentHashTest.php
26 changes: 16 additions & 10 deletions src/Benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
use DateTimeImmutable;
use Exception;

/**
* @codeCoverageIgnore
* @todo Write tests..
*/
class Benchmark {
/**
* @param string[] $algorithms
Expand All @@ -32,6 +28,7 @@ public function getAvailableHashCallbacks(?array $algorithms = null): array {
}

/**
* @codeCoverageIgnore
* @return string[]
* @throws Exception
*/
Expand Down Expand Up @@ -130,6 +127,9 @@ public function sortByTwoColumns(
array_multisort($primaryValues, $primaryDirection, $secondaryValues, $secondaryDirection, $array);
}

/**
* @codeCoverageIgnore
*/
public function printProgress(int $iterationCount, int $totalIterations, DateTimeImmutable $startTime): void {
if($iterationCount % 5 !== 0) {
return;
Expand All @@ -142,6 +142,9 @@ public function printProgress(int $iterationCount, int $totalIterations, DateTim
->format('%H:%I:%S') . PHP_EOL;
}

/**
* @codeCoverageIgnore
*/
public function generateData(int $dataCount): void {
$targetDir = __DIR__ . '/../tmp/benchmark/';

Expand Down Expand Up @@ -171,8 +174,9 @@ protected function formatNumber(int|float $number): string {
/**
* @param array<int, array<string, string|float>> $results
*/
public function printResults(array $results): void {
echo 'Results:' . PHP_EOL;
public function printResults(array $results): string {
$string = 'Results:' . PHP_EOL;

foreach($results as $result) {
$result['name'] = str_pad((string) $result['name'], 5, ' ', STR_PAD_RIGHT);
$result['distribution'] = str_pad((string) $result['distribution'], 5, ' ', STR_PAD_RIGHT);
Expand All @@ -182,15 +186,17 @@ public function printResults(array $results): void {

foreach($result as $title => $value) {
if(in_array($title, ['name', 'distribution'], true)) {
echo '[' . $value . ']';
$string .= '[' . $value . ']';
if($title === 'name') {
echo ' -- ';
$string .= ' -- ';
}
continue;
}
echo $title . ': ' . $value . ' -- ';
$string .= $title . ': ' . $value . ' -- ';
}
echo PHP_EOL;
$string .= PHP_EOL;
}

return $string;
}
}
Loading

0 comments on commit 17b1c10

Please sign in to comment.