Validate precipitation probabilities and ice wording
This commit is contained in:
@@ -2,6 +2,7 @@ package weatherdata
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -93,6 +94,29 @@ func TestForecastPeriodHasUsableTimeBounds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestForecastPeriodHasValidPrecipitationProbability(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
value *float64
|
||||
want bool
|
||||
}{
|
||||
{name: "missing", want: true},
|
||||
{name: "zero", value: ptrProbability(0), want: true},
|
||||
{name: "one hundred", value: ptrProbability(100), want: true},
|
||||
{name: "negative", value: ptrProbability(-0.1)},
|
||||
{name: "above one hundred", value: ptrProbability(100.1)},
|
||||
{name: "not a number", value: ptrProbability(math.NaN())},
|
||||
{name: "infinite", value: ptrProbability(math.Inf(1))},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
period := ForecastPeriod{ProbabilityOfPrecipitationPercent: tt.value}
|
||||
if got := period.HasValidPrecipitationProbability(); got != tt.want {
|
||||
t.Fatalf("HasValidPrecipitationProbability() = %t, want %t", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func mustParseBundleTime(value string) time.Time {
|
||||
parsed, err := time.Parse(time.RFC3339, value)
|
||||
if err != nil {
|
||||
@@ -100,3 +124,7 @@ func mustParseBundleTime(value string) time.Time {
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
func ptrProbability(value float64) *float64 {
|
||||
return &value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user