aboutsummaryrefslogtreecommitdiff
path: root/web/frontend/analytics-logic.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'web/frontend/analytics-logic.test.ts')
-rw-r--r--web/frontend/analytics-logic.test.ts26
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");
+});