diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-21 19:07:31 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-21 19:07:31 +0200 |
| commit | b3a83b2fdd5b406d020398e7c3cf6f46149a2523 (patch) | |
| tree | 7086ae3602e219f7478dcaeca66c0e54e337c1f3 /web/frontend/analytics-logic.test.ts | |
| parent | 1e63f5c91f0e5ff7dfc582b67d262d5939cc34bc (diff) | |
Add global analytics scatter chart
Diffstat (limited to 'web/frontend/analytics-logic.test.ts')
| -rw-r--r-- | web/frontend/analytics-logic.test.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/web/frontend/analytics-logic.test.ts b/web/frontend/analytics-logic.test.ts new file mode 100644 index 0000000..74fdddd --- /dev/null +++ b/web/frontend/analytics-logic.test.ts @@ -0,0 +1,26 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { formatCotacol, formatSpeed, niceStep, ticks } from "./analytics-logic.ts"; + +test("computes a pleasant axis step within a 1-2-5-10 series", () => { + assert.equal(niceStep(25, 5), 5); + assert.equal(niceStep(60, 5), 10); + assert.equal(niceStep(3.6, 5), 0.5); + assert.equal(niceStep(0, 5), 1); +}); + +test("produces ascending ticks that bracket the data range and include its max", () => { + assert.deepEqual(ticks(0, 27.9), [0, 5, 10, 15, 20, 25]); + assert.deepEqual(ticks(0, 315), [0, 50, 100, 150, 200, 250, 300]); + const values = ticks(0, 27.9); + for (let index = 1; index < values.length; index++) { + assert.ok(values[index] > values[index - 1]); + } + assert.ok(values[values.length - 1] <= 27.9 + 1e-9); +}); + +test("formats speed and cotacol per 100 km for axis labels", () => { + assert.equal(formatSpeed(25.2), "25.2"); + assert.equal(formatCotacol(300), "300"); + assert.equal(formatCotacol(50), "50.0"); +}); |
