aboutsummaryrefslogtreecommitdiff
path: root/ride/difficulty_test.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-08-25 13:17:20 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-08-25 13:17:20 +0200
commit87e29e1eb5a113fbb40d452a193219a40780c302 (patch)
tree75e3e62bd49ca8e5ceaa5b40e02291118fa5c970 /ride/difficulty_test.go
parente54e2b313a37c2d2af4e3e537ad4e64e8c816e86 (diff)
Describe test rides as plain strings with a ridetest DSL
Add internal/ridetest parsing "2km at 7% | 1km at -7%" sections into a ride.Ride, with Sampling, StartCoord, StartTime and StartElevation options, plus per-section hr/cad/w metrics. Replace the package-private RideBuilder in climb/difficulty tests and export FromColumnsWithMetrics so metric columns can be built outside the ride package.
Diffstat (limited to 'ride/difficulty_test.go')
-rw-r--r--ride/difficulty_test.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/ride/difficulty_test.go b/ride/difficulty_test.go
index 2e7cf56..bd316b4 100644
--- a/ride/difficulty_test.go
+++ b/ride/difficulty_test.go
@@ -4,35 +4,36 @@ import (
"math"
"testing"
+ "github.com/martinlehoux/biking_home/internal/ridetest"
"github.com/martinlehoux/biking_home/ride"
"github.com/stretchr/testify/assert"
)
func TestCotacolConstantClimb(t *testing.T) {
- r := RideBuilder{precision: 100}.WithSection("2km at 7%").Build()
+ r := ridetest.MustRide("2km at 7%")
assert.InDelta(t, 98.0, ride.Cotacol(r), 1e-9)
}
func TestCotacolIgnoresDescent(t *testing.T) {
- r := RideBuilder{precision: 100}.WithSection("2km at 7%").WithSection("2km at -7%").Build()
+ r := ridetest.MustRide("2km at 7% | 2km at -7%")
assert.InDelta(t, 98.0, ride.Cotacol(r), 1e-9)
}
func TestCotacolFlatIsZero(t *testing.T) {
- r := RideBuilder{precision: 100}.WithSection("5km at 0%").Build()
+ r := ridetest.MustRide("5km at 0%")
assert.Zero(t, ride.Cotacol(r))
}
func TestCotacolSteepShortCountsMore(t *testing.T) {
- steep := RideBuilder{precision: 100}.WithSection("0.5km at 14%").Build()
- long := RideBuilder{precision: 100}.WithSection("1km at 7%").Build()
+ steep := ridetest.MustRide("0.5km at 14%")
+ long := ridetest.MustRide("1km at 7%")
assert.InDelta(t, 98.0, ride.Cotacol(steep), 1e-9)
assert.InDelta(t, 49.0, ride.Cotacol(long), 1e-9)
}
func TestCotacolPrecisionInvariant(t *testing.T) {
- coarse := RideBuilder{precision: 100}.WithSection("3km at 5%").Build()
- fine := RideBuilder{precision: 50}.WithSection("3km at 5%").Build()
+ coarse := ridetest.MustRide("3km at 5%")
+ fine := ridetest.MustRide("3km at 5%", ridetest.Sampling(50))
assert.InDelta(t, ride.Cotacol(coarse), ride.Cotacol(fine), 1e-9)
}
@@ -43,7 +44,7 @@ func TestCotacolExampleRide(t *testing.T) {
}
func TestCotacolClimbNotAtStart(t *testing.T) {
- r := RideBuilder{precision: 100}.WithSection("1km at 0%").WithSection("2km at 7%").Build()
+ r := ridetest.MustRide("1km at 0% | 2km at 7%")
climbs := r.DetectClimbs(nil, ride.ClimbSlopeMinimum)
assert.Len(t, climbs, 1)
assert.InDelta(t, 98.0, climbs[0].DifficultyScore(), 1e-9)