2026-05-01 22:38:44 +08:00
|
|
|
package basic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"math"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type outerPlanetEventBaselineSample struct {
|
|
|
|
|
InputUTC string `json:"input_utc"`
|
|
|
|
|
TTJDBits uint64 `json:"tt_jd_bits"`
|
|
|
|
|
Events map[string]uint64 `json:"events"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type outerPlanetEventBaseline struct {
|
|
|
|
|
Samples []outerPlanetEventBaselineSample `json:"samples"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-15 23:54:15 +08:00
|
|
|
func loadOuterPlanetEventBaseline(t *testing.T, path string, cases []outerPlanetEventCase) outerPlanetEventBaseline {
|
2026-05-01 22:38:44 +08:00
|
|
|
t.Helper()
|
|
|
|
|
|
2026-10-15 23:54:15 +08:00
|
|
|
var named []namedEventFunc
|
|
|
|
|
for _, c := range cases {
|
|
|
|
|
named = append(named, namedEventFunc{c.name, c.fn})
|
2026-05-01 22:38:44 +08:00
|
|
|
}
|
2026-10-15 23:54:15 +08:00
|
|
|
data := eventBaselineData(t, path, named)
|
2026-05-01 22:38:44 +08:00
|
|
|
|
|
|
|
|
var baseline outerPlanetEventBaseline
|
|
|
|
|
if err := json.Unmarshal(data, &baseline); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if len(baseline.Samples) == 0 {
|
|
|
|
|
t.Fatalf("empty baseline: %s", path)
|
|
|
|
|
}
|
|
|
|
|
return baseline
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestOuterPlanetEventBaselineRegression(t *testing.T) {
|
|
|
|
|
for _, plan := range outerPlanetEventPlans() {
|
|
|
|
|
t.Run(plan.planet, func(t *testing.T) {
|
|
|
|
|
cases := plan.allCases()
|
2026-10-15 23:54:15 +08:00
|
|
|
baseline := loadOuterPlanetEventBaseline(t, plan.baselineFile, cases)
|
2026-05-01 22:38:44 +08:00
|
|
|
|
|
|
|
|
for _, sample := range baseline.Samples {
|
|
|
|
|
jd := math.Float64frombits(sample.TTJDBits)
|
|
|
|
|
for _, event := range cases {
|
|
|
|
|
wantBits, ok := sample.Events[event.name]
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatalf("%s missing baseline event %s", sample.InputUTC, event.name)
|
|
|
|
|
}
|
|
|
|
|
want := math.Float64frombits(wantBits)
|
|
|
|
|
got := event.fn(jd)
|
|
|
|
|
diff := math.Abs(got - want)
|
|
|
|
|
if diff > event.tolerance {
|
|
|
|
|
t.Fatalf("%s %s diff %.12f > tolerance %.12f", sample.InputUTC, event.name, diff, event.tolerance)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|