aboutsummaryrefslogtreecommitdiff
path: root/official_climb/official_climb_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'official_climb/official_climb_test.go')
-rw-r--r--official_climb/official_climb_test.go111
1 files changed, 111 insertions, 0 deletions
diff --git a/official_climb/official_climb_test.go b/official_climb/official_climb_test.go
index 2114dd2..a0c8d65 100644
--- a/official_climb/official_climb_test.go
+++ b/official_climb/official_climb_test.go
@@ -138,3 +138,114 @@ func TestMatchClimbRejectsEndpointOutsideRadius(t *testing.T) {
_, found := official_climb.MatchClimb(parsed.Coords, official, 10)
assert.False(t, found)
}
+
+func TestMatchClimbsMatchesTwoLaps(t *testing.T) {
+ coords := []geodist.Coord{
+ {Lat: 43.10, Lon: 5.10},
+ {Lat: 43.11, Lon: 5.11},
+ {Lat: 43.12, Lon: 5.12},
+ {Lat: 43.13, Lon: 5.13},
+ {Lat: 43.10, Lon: 5.10},
+ {Lat: 43.11, Lon: 5.11},
+ {Lat: 43.12, Lon: 5.12},
+ {Lat: 43.13, Lon: 5.13},
+ }
+ parsed := ride.FromColumns(
+ []float64{0, 1000, 2000, 3000, 4000, 5000, 6000, 7000},
+ []float64{100, 150, 200, 100, 100, 150, 200, 100},
+ coords,
+ []time.Time{time.Unix(0, 0), time.Unix(60, 0), time.Unix(120, 0), time.Unix(180, 0), time.Unix(240, 0), time.Unix(300, 0), time.Unix(360, 0), time.Unix(420, 0)},
+ )
+ official := official_climb.OfficialClimb{
+ Name: "Loop",
+ StartCoord: geodist.Coord{Lat: 43.10, Lon: 5.10},
+ EndCoord: geodist.Coord{Lat: 43.12, Lon: 5.12},
+ }
+ matches := official_climb.MatchClimbs(parsed.Coords, official, official_climb.DefaultMatchRadiusM)
+ require.Len(t, matches, 2)
+ assert.Equal(t, 0, matches[0].StartIndex)
+ assert.Equal(t, 2, matches[0].EndIndex)
+ assert.Equal(t, 4, matches[1].StartIndex)
+ assert.Equal(t, 6, matches[1].EndIndex)
+ // Single-match helper still returns first occurrence for backward compatibility.
+ single, found := official_climb.MatchClimb(parsed.Coords, official, official_climb.DefaultMatchRadiusM)
+ require.True(t, found)
+ assert.Equal(t, 0, single.StartIndex)
+}
+
+func TestMatchClimbsMatchesOnlyCompleteLaps(t *testing.T) {
+ coords := []geodist.Coord{
+ {Lat: 43.10, Lon: 5.10},
+ {Lat: 43.11, Lon: 5.11},
+ {Lat: 43.13, Lon: 5.13},
+ {Lat: 43.10, Lon: 5.10},
+ {Lat: 43.11, Lon: 5.11},
+ {Lat: 43.12, Lon: 5.12},
+ }
+ parsed := ride.FromColumns(
+ []float64{0, 1000, 2000, 3000, 4000, 5000},
+ []float64{100, 150, 100, 100, 150, 200},
+ coords,
+ []time.Time{time.Unix(0, 0), time.Unix(60, 0), time.Unix(120, 0), time.Unix(180, 0), time.Unix(240, 0), time.Unix(300, 0)},
+ )
+ official := official_climb.OfficialClimb{
+ Name: "Partial",
+ StartCoord: geodist.Coord{Lat: 43.10, Lon: 5.10},
+ EndCoord: geodist.Coord{Lat: 43.12, Lon: 5.12},
+ }
+ matches := official_climb.MatchClimbs(parsed.Coords, official, official_climb.DefaultMatchRadiusM)
+ require.Len(t, matches, 1)
+ assert.Equal(t, 3, matches[0].StartIndex)
+ assert.Equal(t, 5, matches[0].EndIndex)
+}
+
+func TestMatchClimbsPreservesDirectionAcrossLaps(t *testing.T) {
+ coords := []geodist.Coord{
+ {Lat: 43.12, Lon: 5.12},
+ {Lat: 43.11, Lon: 5.11},
+ {Lat: 43.10, Lon: 5.10},
+ }
+ parsed := ride.FromColumns(
+ []float64{0, 1000, 2000},
+ []float64{200, 150, 100},
+ coords,
+ []time.Time{time.Unix(0, 0), time.Unix(60, 0), time.Unix(120, 0)},
+ )
+ official := official_climb.OfficialClimb{
+ Name: "Directional",
+ StartCoord: geodist.Coord{Lat: 43.10, Lon: 5.10},
+ EndCoord: geodist.Coord{Lat: 43.12, Lon: 5.12},
+ }
+ matches := official_climb.MatchClimbs(parsed.Coords, official, official_climb.DefaultMatchRadiusM)
+ assert.Empty(t, matches)
+}
+
+func TestMatchClimbsClustersContiguousPoints(t *testing.T) {
+ coords := []geodist.Coord{
+ {Lat: 43.1000, Lon: 5.1000},
+ {Lat: 43.1001, Lon: 5.1001},
+ {Lat: 43.1001, Lon: 5.1001},
+ {Lat: 43.11, Lon: 5.11},
+ {Lat: 43.12, Lon: 5.12},
+ {Lat: 43.1000, Lon: 5.1000},
+ {Lat: 43.1001, Lon: 5.1001},
+ {Lat: 43.12, Lon: 5.12},
+ }
+ parsed := ride.FromColumns(
+ []float64{0, 100, 200, 1000, 2000, 3000, 3100, 4000},
+ []float64{100, 101, 102, 150, 200, 100, 101, 200},
+ coords,
+ []time.Time{time.Unix(0, 0), time.Unix(10, 0), time.Unix(20, 0), time.Unix(60, 0), time.Unix(120, 0), time.Unix(180, 0), time.Unix(190, 0), time.Unix(240, 0)},
+ )
+ official := official_climb.OfficialClimb{
+ Name: "Clustered",
+ StartCoord: geodist.Coord{Lat: 43.10, Lon: 5.10},
+ EndCoord: geodist.Coord{Lat: 43.12, Lon: 5.12},
+ }
+ matches := official_climb.MatchClimbs(parsed.Coords, official, official_climb.DefaultMatchRadiusM)
+ require.Len(t, matches, 2)
+ assert.Equal(t, 0, matches[0].StartIndex)
+ assert.Equal(t, 4, matches[0].EndIndex)
+ assert.Equal(t, 5, matches[1].StartIndex)
+ assert.Equal(t, 7, matches[1].EndIndex)
+}