Files
astro/basic/orbital_events_test.go
T
b612 044f2f4381 feat: 引入可切换星历模型并扩展天象观测链路
- 新增半解析、旧模型、自定义与多源堆叠星历实例,提供 Context、Instance、SPK 读取及状态与视位置计算
- 统一太阳、月球和行星实例接口,扩展黄经穿越、留、相位、最近角距、偕日可见、任意高度升落、轨道节点及凌日等天象查询
- 完善日月食、月掩与凌日的月缘剖面、有限盘面接触、站心修正、局地可见性、全球路径和地图输出
- 新增 SVG、GeoJSON、KML 天象输出及凌日、月掩和月缘地形相关缓存与几何求解
- 新增恒星星表导入与查询,支持 CSV、Hipparcos、BSC5、Stellarium 等格式及名称、交叉标识、锥面检索和星等过滤
- 补充 IAU 2006、地球定向、折射消光、大气观测、轨道传播及半解析行星/月球数据支持
- 将默认未来民用时标切换为 TimeScaleLeapHour,更新 2027–2400 农历速查表、中文日期解析和时区边界处理
- 增加事件基线、跨模型回归、几何边界、月缘地形和输出契约测试,完善中英文手册、示例资源、NOTICE 与忽略规则
2026-10-15 23:54:15 +08:00

86 lines
3.0 KiB
Go

// 被测契约:近日点与远日点交替出现且日心距为局部极值;过交点处日心黄纬为零、升降交点交替,并带该时刻的日心距。
package basic
import (
"math"
"testing"
)
func TestPlanetApsidesKnownDates(t *testing.T) {
cases := []struct {
body SkyBody
kind OrbitalEventKind
startTT float64
wantTT float64
tolDays float64
}{
{SkyEarth, OrbitalPerihelion, 2451545, 2451547.2, 1.5},
{SkyMars, OrbitalPerihelion, 2451545, 2452195, 3},
{SkyJupiter, OrbitalPerihelion, 2459000, 2459965, 15},
}
for _, c := range cases {
_, period, _ := orbitalIndex(c.body)
var got float64
for _, e := range PlanetApsidesWithInstance(c.body, c.startTT, c.startTT+1.1*period, nil) {
if e.Kind == c.kind {
got = e.JDE
break
}
}
if math.Abs(got-c.wantTT) > c.tolDays {
t.Errorf("body %d kind %d: got %.2f want %.2f", c.body, c.kind, got, c.wantTT)
}
}
}
func TestPlanetApsidesAlternateAndNodesAreZeroLatitude(t *testing.T) {
for _, body := range []SkyBody{SkyMercury, SkyVenus, SkyMars, SkyJupiter, SkySaturn} {
index, period, _ := orbitalIndex(body)
ap := PlanetApsidesWithInstance(body, 2451545, 2451545+3*period, nil)
if len(ap) < 5 {
t.Fatalf("body %d: only %d apsides", body, len(ap))
}
for i := 1; i < len(ap); i++ {
if ap[i].Kind == ap[i-1].Kind {
t.Errorf("body %d: apsides do not alternate at %d", body, i)
}
}
nodes := PlanetNodesWithInstance(body, 2451545, 2451545+3*period, nil)
if len(nodes) < 5 {
t.Fatalf("body %d: only %d nodes", body, len(nodes))
}
for i, e := range nodes {
if b := PlanetCoordinateNWithInstance(index, 1, e.JDE, -1, nil); math.Abs(b) > 1e-6 {
t.Errorf("body %d node %d: latitude %.3g", body, i, b)
}
if want := PlanetCoordinateNWithInstance(index, 2, e.JDE, -1, nil); math.IsNaN(e.DistanceAU) || math.Abs(e.DistanceAU-want) > 1e-12 {
t.Errorf("body %d node %d: distance %.9f want %.9f", body, i, e.DistanceAU, want)
}
if i > 0 && e.Kind == nodes[i-1].Kind {
t.Errorf("body %d: nodes do not alternate at %d", body, i)
}
}
}
if PlanetNodesWithInstance(SkyEarth, 2451545, 2452545, nil) != nil || PlanetApsidesWithInstance(SkySun, 2451545, 2452545, nil) != nil {
t.Error("unsupported body must return nil")
}
}
func TestPlanetApsidesRejectsUnscannableRange(t *testing.T) {
if got := PlanetApsidesWithInstance(SkyMars, -1e308, 1e308, nil); got != nil {
t.Errorf("huge range: %d events", len(got))
}
if got := PlanetApsidesWithInstance(SkyMars, -1e15, 1e15, nil); got != nil {
t.Errorf("over grid limit: %d events", len(got))
}
if got := PlanetApsidesWithInstance(SkyEarth, 0, 1e12, nil); got != nil {
t.Errorf("over 32-bit grid limit: %d events", len(got))
}
if got := PlanetNodesWithInstance(SkyMars, 0, 1e12, nil); got != nil {
t.Errorf("nodes over grid limit: %d events", len(got))
}
if got := PlanetNodesWithInstance(SkyMars, 0, 686.98/200*float64(skyGridMaxIntervals), nil); got != nil {
t.Errorf("nodes at grid limit: %d events", len(got))
}
}