diff options
Diffstat (limited to 'ride/climb_test.go')
| -rw-r--r-- | ride/climb_test.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ride/climb_test.go b/ride/climb_test.go index c0d4bd6..6b5c097 100644 --- a/ride/climb_test.go +++ b/ride/climb_test.go @@ -169,3 +169,21 @@ func TestDetectClimbsIgnoresOutOfRangeClaim(t *testing.T) { require.Len(t, climbs, 1) assert.Equal(t, "0.0km-2.0km: 2.0km at 7.0% (98 pts - Cat 3)", climbs[0].String()) } + +func TestDetectClimbsWithUnsortedClaimsDropsOverlappingClimb(t *testing.T) { + // Reproduces ride 6 Chemin des Lauriers bug: DetectClimbs must not depend on + // caller-provided order. Two official claims out of ID order (Bastides + // 2140-2627 before Lauriers 1215-1588) caused freeRegions to skip the + // earlier claim and leave the overlapping Cat 4 1352-1601 visible. + // Minimal reproduction: two climbs 0-2km and 3-5km separated by a descent. + r := RideBuilder{precision: 100}.WithSection("2km at 7%").WithSection("1km at -7%").WithSection("2km at 7%").Build() + // Both climbs claimed, but in reverse order (mimics ORDER BY id returning 30-50 before 0-20). + // Sorted input correctly yields 0 detected climbs. + sorted := []ride.Range{{Start: 0, End: 20}, {Start: 30, End: 50}} + assert.Empty(t, r.DetectClimbs(sorted, ride.ClimbSlopeMinimum)) + + unsorted := []ride.Range{{Start: 30, End: 50}, {Start: 0, End: 20}} + climbs := r.DetectClimbs(unsorted, ride.ClimbSlopeMinimum) + // Before fix this fails: freeRegions skips {0,20} because 20 < 30 and returns 1 climb. + assert.Empty(t, climbs, "unsorted claimed ranges must still suppress overlapping climbs — expected 0, got %v", climbs) +} |
