From ff3cd6248f2b78dc76f1ce8cc2337907188fd401 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Tue, 25 Aug 2026 11:24:51 +0200 Subject: 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. --- ride/ecs_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 ride/ecs_test.go (limited to 'ride/ecs_test.go') 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) +} -- cgit v1.3