1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import test from "node:test";
import assert from "node:assert/strict";
import {
categoryForScore,
climbMetrics,
cotacolForClimb,
elevationAtDistance,
formatDistance,
formatElevation,
nearestPointIndex,
} from "../static/ride-detail-logic.js";
const points = [
{ distanceKm: 0, elevationM: 100 },
{ distanceKm: 0.12, elevationM: 106 },
{ distanceKm: 0.2, elevationM: 114 },
{ distanceKm: 0.25, elevationM: 120 },
];
test("finds the nearest profile point by distance", () => {
assert.equal(nearestPointIndex(points, 0.01), 0);
assert.equal(nearestPointIndex(points, 0.15), 1);
assert.equal(nearestPointIndex(points, 0.24), 3);
});
test("interpolates elevation between route points", () => {
assert.equal(elevationAtDistance(points, 0, 100), 105);
assert.equal(elevationAtDistance(points, 2, 250), 120);
});
test("calculates climb metrics with the Cotacol score", () => {
const metrics = climbMetrics(points, { startIndex: 0, endIndex: 3 });
assert.equal(metrics.distanceKm, 0.25);
assert.equal(metrics.elevationGain, 20);
assert.equal(metrics.slope, 8);
assert.equal(metrics.cotacol, cotacolForClimb(points, 0, 3));
assert.equal(metrics.category, categoryForScore(metrics.score));
});
test("formats profile labels consistently", () => {
assert.equal(formatDistance(2.4), "2.4 km");
assert.equal(formatDistance(12.4), "12 km");
assert.equal(formatElevation(123.6), "124 m");
});
|