Skip to content

Commit 45cd480

Browse files
committed
coverage
1 parent d997e23 commit 45cd480

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/histogram.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, test } from 'vitest';
22

3-
import { type Data, histogram } from './histogram.js';
3+
import { type Data, histogram, pointMinMax, valueMinMaxSymbols } from './histogram.js';
44

55
describe('histogram', () => {
66
test('simple', () => {
@@ -223,6 +223,27 @@ describe('histogram', () => {
223223
),
224224
);
225225
});
226+
227+
const U = undefined;
228+
229+
test.each`
230+
value | minVal | maxVal | width | padding | symbols | expected
231+
${0.5} | ${0} | ${1} | ${11} | ${' '} | ${valueMinMaxSymbols} | ${'┣━━━━●━━━━┫'}
232+
${0.5} | ${0} | ${1} | ${11} | ${U} | ${undefined} | ${'┣━━━━●━━━━┫'}
233+
${0.5} | ${U} | ${U} | ${11} | ${'.'} | ${undefined} | ${'.....●.....'}
234+
${0.6} | ${0} | ${1.0} | ${11} | ${' '} | ${valueMinMaxSymbols} | ${'┣━━━━━●━━━┫'}
235+
${0.6} | ${0} | ${0.6} | ${11} | ${' '} | ${valueMinMaxSymbols} | ${'┣━━━━━● '}
236+
${0.6} | ${0} | ${0.6} | ${11} | ${'.'} | ${valueMinMaxSymbols} | ${'┣━━━━━●....'}
237+
${0.6} | ${0.6} | ${1} | ${11} | ${'.'} | ${valueMinMaxSymbols} | ${'......●━━━┫'}
238+
${0.5} | ${0.4} | ${0.8} | ${11} | ${'.'} | ${undefined} | ${'....┣●━━┫..'}
239+
`(
240+
'pointMinMax $value, $minVal, $maxVal, $width, $padding, $symbols',
241+
({ value, minVal, maxVal, width, padding, symbols, expected }) => {
242+
const r = pointMinMax(value, minVal, maxVal, width, padding, symbols);
243+
expect(r.length).toBe(width);
244+
expect(r).toBe(expected);
245+
},
246+
);
226247
});
227248

228249
function sampleData(num: number, scale = 1, step = 5): Data {

src/histogram.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function calc(value: number, width: number): number {
183183
return Math.floor(v * (width - 1) + 0.5);
184184
}
185185

186-
const valueMinMaxSymbols = [
186+
export const valueMinMaxSymbols: readonly string[] = [
187187
'●',
188188
boxSymbols[BoxSymbol.leftT],
189189
boxSymbols[BoxSymbol.horizontal],
@@ -222,7 +222,7 @@ export function pointMinMax(
222222
}
223223

224224
function sLen(s: string | undefined): number {
225-
if (s === undefined) return 0;
225+
if (!s) return 0;
226226
return [...s].length;
227227
}
228228

0 commit comments

Comments
 (0)