aboutsummaryrefslogtreecommitdiff
path: root/mountain_pass
diff options
context:
space:
mode:
Diffstat (limited to 'mountain_pass')
-rw-r--r--mountain_pass/detection_test.go52
1 files changed, 21 insertions, 31 deletions
diff --git a/mountain_pass/detection_test.go b/mountain_pass/detection_test.go
index 39bb9ae..6318ca3 100644
--- a/mountain_pass/detection_test.go
+++ b/mountain_pass/detection_test.go
@@ -1,11 +1,12 @@
package mountain_pass_test
import (
+ "fmt"
"testing"
- "time"
"github.com/jftuga/geodist"
"github.com/martinlehoux/biking_home/internal/dbtest"
+ "github.com/martinlehoux/biking_home/internal/ridetest"
"github.com/martinlehoux/biking_home/mountain_pass"
"github.com/martinlehoux/biking_home/ride"
"github.com/stretchr/testify/assert"
@@ -40,12 +41,7 @@ func TestLoadMountainPassesAroundRideUsesExpandedBounds(t *testing.T) {
)
require.NoError(t, err)
- route := ride.FromColumns(
- []float64{0, 1000},
- []float64{100, 200},
- []geodist.Coord{{Lat: 43.0, Lon: 5.0}, {Lat: 43.1, Lon: 5.1}},
- make([]time.Time, 2),
- )
+ route := ridetest.MustRide("1km at 10%", ridetest.StartCoord(43.0, 5.0), ridetest.Heading(0.1, 0.1), ridetest.StartElevation(100), ridetest.Sampling(1000))
passes, err := mountain_pass.LoadMountainPassesAroundRide(db, route.Coords(), 10_000)
require.NoError(t, err)
require.Len(t, passes, 3)
@@ -99,22 +95,19 @@ func TestDetectCrossingsRequiresElevationAgreement(t *testing.T) {
assert.Empty(t, mountain_pass.DetectCrossings(r.Coords(), r.Distances(), r.Elevations(), []mountain_pass.MountainPass{pass}, 100, 25))
}
+// rideFromPoint builds a 1 km ride ending at (latitude, longitude) at the
+// given elevation, starting 0.01° southwest at 100 m.
func rideFromPoint(t *testing.T, latitude, longitude, elevation float64) ride.Ride {
t.Helper()
- return ride.FromColumns(
- []float64{0, 1000},
- []float64{100, elevation},
- []geodist.Coord{{Lat: latitude - 0.01, Lon: longitude - 0.01}, {Lat: latitude, Lon: longitude}},
- make([]time.Time, 2),
- )
+ slopePercent := (elevation - 100) / 10 // gain over a 1 km ride, as a percentage
+ return ridetest.MustRide(fmt.Sprintf("1km at %v%%", slopePercent),
+ ridetest.StartCoord(latitude-0.01, longitude-0.01),
+ ridetest.StartElevation(100),
+ ridetest.Sampling(1000))
}
func TestMatchClimbFindsPassAtTop(t *testing.T) {
- climb := climbFromColumns(
- []float64{0, 1000, 2000},
- []float64{300, 447, 380},
- []geodist.Coord{{Lat: 43.61, Lon: 5.42}, {Lat: 43.62, Lon: 5.43}, {Lat: 43.63, Lon: 5.44}},
- )
+ climb := climbFixture()
pass := mountain_pass.MountainPass{
Name: "Pas de Magnan", Elevation: 440,
Coord: &geodist.Coord{Lat: 43.62, Lon: 5.43},
@@ -125,11 +118,7 @@ func TestMatchClimbFindsPassAtTop(t *testing.T) {
}
func TestMatchClimbRequiresElevationAgreement(t *testing.T) {
- climb := climbFromColumns(
- []float64{0, 1000, 2000},
- []float64{300, 447, 380},
- []geodist.Coord{{Lat: 43.61, Lon: 5.42}, {Lat: 43.62, Lon: 5.43}, {Lat: 43.63, Lon: 5.44}},
- )
+ climb := climbFixture()
pass := mountain_pass.MountainPass{
Name: "Pas de Magnan", Elevation: 900,
Coord: &geodist.Coord{Lat: 43.62, Lon: 5.43},
@@ -139,11 +128,7 @@ func TestMatchClimbRequiresElevationAgreement(t *testing.T) {
}
func TestMatchClimbNearestOfTwo(t *testing.T) {
- climb := climbFromColumns(
- []float64{0, 1000, 2000},
- []float64{300, 447, 380},
- []geodist.Coord{{Lat: 43.61, Lon: 5.42}, {Lat: 43.62, Lon: 5.43}, {Lat: 43.63, Lon: 5.44}},
- )
+ climb := climbFixture()
near := mountain_pass.MountainPass{
Name: "Pas de Magnan", Elevation: 440,
Coord: &geodist.Coord{Lat: 43.62, Lon: 5.43},
@@ -157,7 +142,12 @@ func TestMatchClimbNearestOfTwo(t *testing.T) {
assert.Equal(t, "Pas de Magnan", matched.Name)
}
-func climbFromColumns(distances, elevations []float64, coords []geodist.Coord) ride.Climb {
- ride := ride.FromColumns(distances, elevations, coords, make([]time.Time, len(distances)))
- return ride.ClimbFromDist(0, 2000)
+// climbFixture builds a 2 km climb from 300 m up to 447 m then back down to
+// 380 m, heading northeast from (43.61, 5.42).
+func climbFixture() ride.Climb {
+ r := ridetest.MustRide("1km at 14.7% | 1km at -6.7%",
+ ridetest.StartCoord(43.61, 5.42),
+ ridetest.StartElevation(300),
+ ridetest.Sampling(1000))
+ return r.ClimbFromDist(0, 2000)
}