diff options
Diffstat (limited to 'mountain_pass/detection_test.go')
| -rw-r--r-- | mountain_pass/detection_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/mountain_pass/detection_test.go b/mountain_pass/detection_test.go index d6cba9f..d86e67b 100644 --- a/mountain_pass/detection_test.go +++ b/mountain_pass/detection_test.go @@ -5,9 +5,11 @@ import ( "time" "github.com/jftuga/geodist" + "github.com/martinlehoux/biking_home/internal/dbtest" "github.com/martinlehoux/biking_home/mountain_pass" "github.com/martinlehoux/biking_home/ride" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestDetectCrossingsFindsPass(t *testing.T) { @@ -23,6 +25,34 @@ func TestDetectCrossingsFindsPass(t *testing.T) { assert.Less(t, crossings[0].ElevationDiff, 25.0) } +func TestLoadMountainPassesAroundRideUsesExpandedBounds(t *testing.T) { + db := dbtest.New(t) + _, err := db.Exec(` + INSERT INTO mountain_passes (external_id, name, country_code, department_code, elevation, latitude, longitude) + VALUES (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?) + `, + "550e8400-e29b-41d4-a716-446655440000", "On route", "FR", "13", 400, 43.05, 5.05, + "6ba7b810-9dad-41d1-80b4-00c04fd430c8", "Within margin", "FR", "13", 500, 43.18, 5.20, + "6ba7b811-9dad-41d1-80b4-00c04fd430c8", "Outside margin", "FR", "13", 600, 43.21, 5.20, + "6ba7b812-9dad-41d1-80b4-00c04fd430c8", "Missing coordinates", "FR", "13", 700, nil, nil, + "6ba7b813-9dad-41d1-80b4-00c04fd430c8", "On route edge", "FR", "13", 300, 43.10, 5.10, + ) + 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), + ) + passes, err := mountain_pass.LoadMountainPassesAroundRide(db, route, 10_000) + require.NoError(t, err) + require.Len(t, passes, 3) + assert.Equal(t, "On route edge", passes[0].Name) + assert.Contains(t, []string{passes[1].Name, passes[2].Name}, "On route") + assert.Contains(t, []string{passes[1].Name, passes[2].Name}, "Within margin") +} + func TestDetectCrossingsIgnoresDistantPass(t *testing.T) { r := rideFromPoint(t, 43.62, 5.43, 447) far := mountain_pass.MountainPass{ |