Skip to content

Commit d973fea

Browse files
committed
apply suggestions
* fix handling of single digit range
1 parent 004ab16 commit d973fea

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/extractRangeInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export function extractRangeInfo(range: string | undefined): { prefix: string; v
33
return undefined;
44
}
55

6-
const matches = range.match(/(?<prefix>(\+-|±)\s*)(?<value>\d.+)/);
6+
const matches = range.match(/(?<prefix>(\+-|±)\s*)(?<value>\d.*)/);
77

88
if (!matches || !matches.groups) {
99
return undefined;

src/normalizeBenchmarkResult.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import { extractRangeInfo } from './extractRangeInfo';
44

55
export function normalizeBenchmarkResult(
66
prevBenchResult: BenchmarkResult | undefined | null,
7-
currenBenchResult: BenchmarkResult,
7+
currentBenchResult: BenchmarkResult,
88
): BenchmarkResult {
99
if (!prevBenchResult) {
10-
return currenBenchResult;
10+
return currentBenchResult;
1111
}
1212

1313
const prevUnit = prevBenchResult.unit;
14-
const currentUnit = currenBenchResult.unit;
15-
const currentRange = currenBenchResult.range;
14+
const currentUnit = currentBenchResult.unit;
15+
const currentRange = currentBenchResult.range;
1616
const currentRangeInfo = extractRangeInfo(currentRange);
1717

18-
const normalizedValue = normalizeValueByUnit(prevUnit, currentUnit, currenBenchResult.value);
19-
const normalizedUnit = currenBenchResult.value !== normalizedValue ? prevUnit : currentUnit;
18+
const normalizedValue = normalizeValueByUnit(prevUnit, currentUnit, currentBenchResult.value);
19+
const normalizedUnit = currentBenchResult.value !== normalizedValue ? prevUnit : currentUnit;
2020
const normalizedRangeInfo = currentRangeInfo
2121
? {
2222
prefix: currentRangeInfo.prefix,
@@ -25,7 +25,7 @@ export function normalizeBenchmarkResult(
2525
: undefined;
2626

2727
return {
28-
...currenBenchResult,
28+
...currentBenchResult,
2929
value: normalizedValue,
3030
unit: normalizedUnit,
3131
range: normalizedRangeInfo ? `${normalizedRangeInfo.prefix}${normalizedRangeInfo.value}` : currentRange,

test/extractRangeInfo.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ describe('extractRangeInfo', () => {
1717
expect(extractRangeInfo('+- 20')).toEqual({ value: 20, prefix: '+- ' });
1818
});
1919

20+
it('should extract single-digit integer', () => {
21+
expect(extractRangeInfo('±2')).toEqual({ value: 2, prefix: '±' });
22+
});
23+
it('should extract decimal and preserve prefix space', () => {
24+
expect(extractRangeInfo('± 0.5')).toEqual({ value: 0.5, prefix: '± ' });
25+
});
26+
it('should extract scientific notation', () => {
27+
expect(extractRangeInfo('+-1e-3')).toEqual({ value: 1e-3, prefix: '+-' });
28+
});
29+
it('should tolerate surrounding whitespace', () => {
30+
expect(extractRangeInfo(' ±20 ')).toEqual({ value: 20, prefix: '±' });
31+
});
32+
2033
it('should NOT extract range with unknown prefix', () => {
2134
expect(extractRangeInfo('unknown prefix 20')).toBeUndefined();
2235
});

0 commit comments

Comments
 (0)