diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-03 08:25:07 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-03 08:25:07 +0200 |
| commit | 9707f9ad09db935af7d06b5de08bc52de13ba6a7 (patch) | |
| tree | 34bcd01e5eda302a8730bf0817d5dd7e82186359 /osmpass/extract_test.go | |
| parent | f06a10982ab9d5aaa7d31cea31964431fa75f253 (diff) | |
feat: Detect mountain pass crossings, name climbs after passes, render ride charts
- osmpass: extract mountain_pass=yes nodes from an OSM PBF, enrich centcols passes with OSM coordinates, resumable -fetch-osm download
- mountain_pass: DetectCrossings for a ride, MatchClimb to name a climb after the pass it tops
- ride: expose Points(), add Climb.Top() and Climb.Name
- chart: -chart renders elevation profile with climb bands and pass markers
- commands: -fetch-osm, -extract-osm, -import-cached, -enrich
Diffstat (limited to 'osmpass/extract_test.go')
| -rw-r--r-- | osmpass/extract_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/osmpass/extract_test.go b/osmpass/extract_test.go new file mode 100644 index 0000000..bd31ebb --- /dev/null +++ b/osmpass/extract_test.go @@ -0,0 +1,49 @@ +package osmpass + +import ( + "testing" + + "github.com/paulmach/osm" + "github.com/stretchr/testify/assert" +) + +func TestIsMountainPass(t *testing.T) { + cases := []struct { + name string + tags map[string]string + want bool + }{ + {"tagged", map[string]string{"mountain_pass": "yes", "name": "Col de la Gineste"}, true}, + {"legacy natural", map[string]string{"natural": "mountain_pass"}, true}, + {"not a pass", map[string]string{"natural": "saddle", "name": "Col de la Gineste"}, false}, + {"no tags", map[string]string{}, false}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + node := &osm.Node{Tags: osm.Tags{}} + for key, value := range c.tags { + node.Tags = append(node.Tags, osm.Tag{Key: key, Value: value}) + } + assert.Equal(t, c.want, isMountainPass(node)) + }) + } +} + +func TestParseElevation(t *testing.T) { + cases := []struct { + input string + want int + ok bool + }{ + {"1320", 1320, true}, + {"1320 m", 1320, true}, + {" 447.5", 447, true}, + {"", 0, false}, + {"unknown", 0, false}, + } + for _, c := range cases { + value, ok := parseElevation(c.input) + assert.Equal(t, c.want, value) + assert.Equal(t, c.ok, ok) + } +} |