From b3a83b2fdd5b406d020398e7c3cf6f46149a2523 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Fri, 21 Aug 2026 19:07:31 +0200 Subject: Add global analytics scatter chart --- web/frontend/analytics-logic.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 web/frontend/analytics-logic.test.ts (limited to 'web/frontend/analytics-logic.test.ts') 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"); +}); -- cgit v1.3