Skip to content

Commit 01b82e4

Browse files
Fix zero comparison for JSON integers and add test
1 parent 0ec825c commit 01b82e4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

benchmark/BenchmarkComparator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private static function compareMetric(array $base, array $cur, float $threshold)
8383
$curVal = $cur['value'];
8484
$unit = $cur['unit'];
8585

86-
if ($baseVal === 0.0) {
86+
if ($baseVal == 0) {
8787
return [
8888
'name' => $cur['name'],
8989
'baseline' => self::formatValue($baseVal, $unit),

tests/Benchmark/BenchmarkComparatorTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,23 @@ public function testBaselineZeroValue(): void
133133
self::assertStringNotContainsString('NAN', $result);
134134
}
135135

136+
public function testBaselineIntegerZeroFromJson(): void
137+
{
138+
// JSON decodes 0 as int(0), not float(0.0)
139+
$baseline = [
140+
['name' => 'insert (ops/s)', 'unit' => 'ops/s', 'value' => 0],
141+
];
142+
$current = [
143+
['name' => 'insert (ops/s)', 'unit' => 'ops/s', 'value' => 10000],
144+
];
145+
146+
$result = BenchmarkComparator::compare($baseline, $current);
147+
148+
self::assertStringNotContainsString('INF', $result);
149+
self::assertStringNotContainsString('NAN', $result);
150+
self::assertStringContainsString('N/A', $result);
151+
}
152+
136153
public function testNewMetricInCurrent(): void
137154
{
138155
$baseline = [

0 commit comments

Comments
 (0)