aboutsummaryrefslogtreecommitdiff
path: root/ride/moving_time_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'ride/moving_time_test.go')
-rw-r--r--ride/moving_time_test.go30
1 files changed, 28 insertions, 2 deletions
diff --git a/ride/moving_time_test.go b/ride/moving_time_test.go
index 402726f..06f9998 100644
--- a/ride/moving_time_test.go
+++ b/ride/moving_time_test.go
@@ -1,6 +1,7 @@
package ride_test
import (
+ "fmt"
"strings"
"testing"
"time"
@@ -25,6 +26,17 @@ func trackPoint(lat, lon string, timestamp string) string {
`</trkpt>`
}
+func metricTrackPoint(lat, lon, timestamp string, cadence, power int) string {
+ return `<trkpt lat="` + lat + `" lon="` + lon + `">` +
+ `<ele>100</ele>` +
+ `<time>` + timestamp + `</time>` +
+ `<extensions><gpxtpx:TrackPointExtension>` +
+ `<gpxtpx:cad>` + fmt.Sprint(cadence) + `</gpxtpx:cad>` +
+ `<gpxtpx:watts>` + fmt.Sprint(power) + `</gpxtpx:watts>` +
+ `</gpxtpx:TrackPointExtension></extensions>` +
+ `</trkpt>`
+}
+
func TestMovingTimeCountsSteadyRiding(t *testing.T) {
parsed := gpxWithPoints(t,
trackPoint("43.0", "5.0", "2026-01-01T10:00:00Z")+
@@ -55,6 +67,20 @@ func TestMovingTimeExcludesLunchBreak(t *testing.T) {
assert.Equal(t, time.Minute, ride.MovingTime(parsed))
}
+func TestMovingTimeCountsEffortMetricsWhenGPSSpeedIsLow(t *testing.T) {
+ data := parserTestGPXMetricsPrefix +
+ metricTrackPoint("43.0", "5.0", "2026-01-01T10:00:00Z", 0, 0) +
+ metricTrackPoint("43.000001", "5.0", "2026-01-01T10:01:00Z", 80, 0) +
+ metricTrackPoint("43.000002", "5.0", "2026-01-01T10:02:00Z", 0, 50) +
+ metricTrackPoint("43.000003", "5.0", "2026-01-01T10:03:00Z", 0, 10) +
+ metricTrackPoint("43.000004", "5.0", "2026-01-01T10:04:00Z", 0, 0) +
+ parserTestGPXSuffix
+ parsed, err := (ride.GPXRideParser{}).Parse(strings.NewReader(data))
+ require.NoError(t, err)
+
+ assert.Equal(t, 2*time.Minute, ride.MovingTime(parsed))
+}
+
func TestMovingTimeWithoutTimestamps(t *testing.T) {
data := parserTestGPXPrefix +
`<trkpt lat="43.0" lon="5.0"><ele>100</ele></trkpt>` +
@@ -68,5 +94,5 @@ func TestMovingTimeWithoutTimestamps(t *testing.T) {
}
func TestMovingTimeAlgorithmVersion(t *testing.T) {
- assert.Equal(t, "v1", ride.MovingTimeAlgorithmVersion)
-} \ No newline at end of file
+ assert.Equal(t, "v2", ride.MovingTimeAlgorithmVersion)
+}