From 0e27097e3d706e0e5bd761bf35fe301fd119d2a9 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Fri, 21 Aug 2026 11:09:29 +0200 Subject: refactor(ride): express category thresholds as inclusive min scores --- ride/difficulty_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'ride/difficulty_test.go') diff --git a/ride/difficulty_test.go b/ride/difficulty_test.go index 142ac0a..5773376 100644 --- a/ride/difficulty_test.go +++ b/ride/difficulty_test.go @@ -1,6 +1,7 @@ package ride_test import ( + "math" "testing" "github.com/martinlehoux/biking_home/ride" @@ -48,6 +49,32 @@ func TestCotacolClimbNotAtStart(t *testing.T) { assert.InDelta(t, 98.0, climbs[0].DifficultyScore(), 1e-9) } +func TestCategoryOfBoundaries(t *testing.T) { + cases := []struct { + score float64 + want ride.Category + }{ + {-5, ride.CategoryNo}, + {30, ride.CategoryNo}, + {35, ride.CategoryFour}, // 35 is the first floor, not below it + {79, ride.CategoryFour}, + {80, ride.CategoryThree}, + {179, ride.CategoryThree}, + {180, ride.CategoryTwo}, + {249, ride.CategoryTwo}, + {250, ride.CategoryOne}, + {599, ride.CategoryOne}, + {600, ride.CategoryHC}, + {700, ride.CategoryHC}, + {math.NaN(), ride.CategoryHC}, // reaches no floor, like the original switch default + } + for _, c := range cases { + assert.Equal(t, c.want, ride.CategoryOf(c.score), "score %v", c.score) + } + assert.Equal(t, "Cat 1", ride.CategoryOne.String()) + assert.Equal(t, "NO", ride.CategoryNo.String()) +} + func TestCotacolHautacamClimbfinderReference(t *testing.T) { r, err := ride.ParseFile(parser, "../examples/2022-07-21.Pogacar.gpx") assert.NoError(t, err) -- cgit v1.3