Files
astro/planet/planet_test.go
T
b612 2bf8478639 feat: 完善日月食与月掩几何链路并扩展历法接口
- 新增日月食中心带、偏食带、阴影足迹、等时线、食分线及升落边界计算,支持极区与混合食拓扑
- 新增日食单时刻阴影求解器、站心状态查询、批量采样和 ΔT 覆盖接口
- 重构恒星与行星月掩路径,补充有限盘面接触、站心修正、掩带宽度、极区投影及升落边界
- 扩展 SVG 与 GeoJSON 输出,支持详细面板、全球/极区/地球投影、边界闭合、时间标记和拓扑签名
- 扩展日月食候选搜索、局地搜索、沙罗序列预计算与范围外推,补充系列锚点和成员一致性校验
- 补齐古历纪年、儒略历独有闰日、多公历候选、历法改革跨日及精确日期运算接口
- 优化 ΔT、章动、恒星时、月球地平线、事件根搜索和本地星历缓存,降低重复计算开销并提升边界稳定
2026-09-17 12:27:40 +08:00

105 lines
2.7 KiB
Go

package planet
import (
"math"
"testing"
)
func TestPlanetViewsMatchRawCuts(t *testing.T) {
views := planetViews()
for bodyIndex, raw := range planetRawData {
view := views[bodyIndex]
if math.Float64bits(view.scale) != math.Float64bits(raw[0]) {
t.Fatalf("body=%d scale mismatch", bodyIndex)
}
for zn := 0; zn < 3; zn++ {
pn := zn*6 + 1
for order := 0; order < 6; order++ {
start := int(raw[pn+order])
end := int(raw[pn+order+1])
if len(view.coords[zn].orders[order]) != end-start {
t.Fatalf("body=%d zn=%d order=%d got=%d want=%d", bodyIndex, zn, order, len(view.coords[zn].orders[order]), end-start)
}
}
}
}
}
func TestBuildPlanetViewsRejectsInvalidCuts(t *testing.T) {
_, err := buildPlanetViews([][]float64{{
10000000000,
20, 21, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20,
}})
if err == nil {
t.Fatal("expected invalid cut error")
}
}
func TestWherePlanetDomainGuards(t *testing.T) {
jds := []float64{2415020.123456789, 2451545.0, 2469808.7654321}
for _, jd := range jds {
for xt := -1; xt <= 7; xt++ {
for zn := 0; zn <= 2; zn++ {
for _, n := range []int{-1, 0, 3, 100} {
got := WherePlanetN(xt, zn, jd, n)
if math.IsNaN(got) || math.IsInf(got, 0) {
t.Fatalf("in-domain WherePlanetN(%d, %d, %v, %d) = %v", xt, zn, jd, n, got)
}
}
got := WherePlanet(xt, zn, jd)
if math.IsNaN(got) || math.IsInf(got, 0) {
t.Fatalf("in-domain WherePlanet(%d, %d, %v) = %v", xt, zn, jd, got)
}
}
}
for _, xt := range []int{-2, -100, 8, 9, 100} {
for zn := 0; zn <= 2; zn++ {
assertWherePlanetNaN(t, xt, zn, jd)
}
}
for _, zn := range []int{-1, -100, 3, 100} {
for xt := -1; xt <= 7; xt++ {
assertWherePlanetNaN(t, xt, zn, jd)
}
}
}
}
func assertWherePlanetNaN(t *testing.T, xt, zn int, jd float64) {
t.Helper()
if got := WherePlanet(xt, zn, jd); !math.IsNaN(got) {
t.Fatalf("WherePlanet(%d, %d, %v) = %v, want NaN", xt, zn, jd, got)
}
for _, n := range []int{-1, 0, 6} {
if got := WherePlanetN(xt, zn, jd, n); !math.IsNaN(got) {
t.Fatalf("WherePlanetN(%d, %d, %v, %d) = %v, want NaN", xt, zn, jd, n, got)
}
}
}
func TestWherePlanetGoldenValues(t *testing.T) {
jd := 2451545.0
cases := []struct {
xt, zn int
want float64
}{
{-1, 0, 100.37782037193487},
{-1, 1, -0.00022991463883506049},
{-1, 2, 0.98332764743480028},
{0, 0, 280.37782037193489},
{0, 1, 0.00022991463883506049},
{0, 2, 0.98332764743480028},
{4, 0, 36.29462069188007},
{4, 1, -1.1745385942079292},
{4, 2, 4.9653814383525443},
}
for _, tc := range cases {
got := WherePlanet(tc.xt, tc.zn, jd)
if math.Abs(got-tc.want) > 1e-12 {
t.Fatalf("WherePlanet(%d, %d, %v) = %.17g, want %.17g", tc.xt, tc.zn, jd, got, tc.want)
}
}
}