package parser import ( "math" "testing" ) func TestParseKM(t *testing.T) { tests := []struct { input string wantKM float64 wantOK bool }{ {"Rode 25km today!", 25, true}, {"Great 25.5 km ride", 25.5, true}, {"Did 25,5km on Zwift", 25.5, true}, {"50KM morning loop", 50, true}, {"100 kilometers on the gravel bike", 100, true}, {"30 miles today", 30 * miToKM, true}, {"Did a 100k ride", 100, true}, {"Went for a 80k loop", 80, true}, {"5,981.9 miles", 5981.9 * miToKM, true}, {"1,000km ride", 1000, true}, // Should NOT match — no cycling context for bare "k" {"Listened to 100k songs", 0, false}, // No distance at all {"Great weather today!", 0, false}, {"PR on the climb!", 0, false}, } for _, tt := range tests { t.Run(tt.input, func(t *testing.T) { got, ok := ParseKM(tt.input) if ok != tt.wantOK { t.Errorf("ParseKM(%q) ok=%v, want %v", tt.input, ok, tt.wantOK) return } if tt.wantOK && math.Abs(got-tt.wantKM) > 0.01 { t.Errorf("ParseKM(%q) = %.2f, want %.2f", tt.input, got, tt.wantKM) } }) } }