43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package changes
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/module"
|
|
)
|
|
|
|
func TestCompareThreeDayDetectsDayChanges(t *testing.T) {
|
|
previous := outlookSnapshot(t, "2026-05-29", "70", 20, "9 AM", false)
|
|
current := outlookSnapshot(t, "2026-05-29", "78", 70, "12 PM", true)
|
|
|
|
changes, err := CompareThreeDay(previous, current, Thresholds{
|
|
TemperatureDegrees: 5,
|
|
PrecipProbabilityPoints: 20,
|
|
PrecipTimingShiftMinutes: 120,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CompareThreeDay() error = %v", err)
|
|
}
|
|
|
|
if len(changes) == 0 {
|
|
t.Fatal("changes length = 0, want detected 3-day changes")
|
|
}
|
|
if countType(changes, "outlook_precip_probability_change") == 0 || countType(changes, "outlook_snow_risk_change") == 0 {
|
|
t.Fatalf("changes = %#v, want precipitation and snow changes", changes)
|
|
}
|
|
}
|
|
|
|
func outlookSnapshot(t *testing.T, date string, tempRange string, precip int, precipTime string, snow bool) module.Snapshot {
|
|
t.Helper()
|
|
return snapshot(t, module.Output{ID: module.DerivedDaypartSummaries, StanzaName: "derived_daypart_summaries", Value: map[string]daypartSummaryStanza{
|
|
date + "_morning": {
|
|
Date: date,
|
|
Period: date + " at 6:00 AM to " + date + " at 10:00 AM",
|
|
TempRangeF: tempRange,
|
|
MaxPopPercent: &precip,
|
|
MaxPopTime: precipTime,
|
|
Snow: snow,
|
|
},
|
|
}})
|
|
}
|