aboutsummaryrefslogtreecommitdiff
path: root/cli/cli_test.go
blob: 6a3e14807e86dfce3ea7ddbd58dd8baf5ea02d54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

package cli

import (
	"testing"

	"github.com/martinlehoux/biking_home/rides"
	"github.com/stretchr/testify/assert"
)

func TestBacktestEligibilityExcludesShortDistances(t *testing.T) {
	short := rides.Ride{GPXPath: "ride.gpx", DistanceM: 10_000 - 1, MovingTimeS: 1}
	minimum := rides.Ride{GPXPath: "ride.gpx", DistanceM: 10_000, MovingTimeS: 1}

	assert.False(t, isBacktestEligible(short))
	assert.True(t, isBacktestEligible(minimum))
}

func TestBacktestStatsUseUnroundedSamples(t *testing.T) {
	absErrors := []float64{0, 0.1, 0.1}

	assert.InDelta(t, 1.0/15, meanAbsErr(absErrors), 1e-12)
	assert.InDelta(t, 1.0/30, stdErrAbsErr(absErrors), 1e-12)
}

func TestErrorDistributionUsesNearestRank(t *testing.T) {
	distribution := errorDistribution([]float64{1, 2, 3, 4}, []float64{50, 75, 99})

	assert.Equal(t, 2.0, distribution[50])
	assert.Equal(t, 3.0, distribution[75])
	assert.Equal(t, 4.0, distribution[99])
}