diff options
Diffstat (limited to 'ride/difficulty_test.go')
| -rw-r--r-- | ride/difficulty_test.go | 17 |
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) |
