diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-25 11:24:51 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-25 11:24:51 +0200 |
| commit | ff3cd6248f2b78dc76f1ce8cc2337907188fd401 (patch) | |
| tree | 59cb08531d7a7087a0a71c2306ce73330527c8d4 /ride/ecs_test.go | |
| parent | 9c2337b50a52ee95011028f6193e0c56aa1fc9d4 (diff) | |
Expose ride data as components and make algorithms consume only the slices they read
Ride now exposes its columns as component getters (Distances, Elevations,
Coords, Timestamps, and the optional Powers, Cadences, HeartRates) with the
coords field unexported. difficultyScore, movingTime, Slope and the climb
detection internals are pure functions over the specific slices they use,
and Climb carries only the component slices it needs instead of a whole
Ride.
Diffstat (limited to 'ride/ecs_test.go')
| -rw-r--r-- | ride/ecs_test.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/ride/ecs_test.go b/ride/ecs_test.go new file mode 100644 index 0000000..01c0628 --- /dev/null +++ b/ride/ecs_test.go @@ -0,0 +1,43 @@ +package ride + +import ( + "testing" + "time" + + "github.com/jftuga/geodist" + "github.com/stretchr/testify/assert" +) + +func TestRideExposesComponentGetters(t *testing.T) { + distances := []float64{0, 500, 1000} + elevations := []float64{0, 35, 70} + coords := []geodist.Coord{{Lat: 43.0, Lon: 5.0}, {Lat: 43.1, Lon: 5.1}, {Lat: 43.2, Lon: 5.2}} + timestamps := []time.Time{{}, time.Time{}.Add(time.Second), time.Time{}.Add(2 * time.Second)} + + r := FromColumns(distances, elevations, coords, timestamps) + + assert.Equal(t, distances, r.Distances()) + assert.Equal(t, elevations, r.Elevations()) + assert.Equal(t, coords, r.Coords()) + assert.Equal(t, timestamps, r.Timestamps()) + + powers, ok := r.Powers() + assert.False(t, ok, "no power component present") + assert.Nil(t, powers) + cadences, ok := r.Cadences() + assert.False(t, ok, "no cadence component present") + assert.Nil(t, cadences) +} + +func TestDifficultyScoreReadsOnlyDistanceAndElevationComponents(t *testing.T) { + // A 1 km climb at a steady 7%, sampled every 100 m. + distances := make([]float64, 0, 11) + elevations := make([]float64, 0, 11) + for i := 0; i <= 10; i++ { + distances = append(distances, float64(i*100)) + elevations = append(elevations, float64(i*7)) + } + + // Reference Cotacol value: 10 segments of 100 m at 7% => 49 pts. + assert.InDelta(t, 49, difficultyScore(distances, elevations, 0, len(distances)-1), 0.5) +} |
