Files
astro/ephemeris_public_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

76 lines
2.8 KiB
Go

package astro_test
import (
"errors"
"math"
"testing"
"time"
"b612.me/astro"
"b612.me/astro/basic"
"b612.me/astro/eclipse"
"b612.me/astro/planet/spk"
)
type publicEphemerisEngine struct{}
func (publicEphemerisEngine) State(target, center astro.Body, jde float64) ([3]float64, [3]float64, error) {
return [3]float64{149597870.7, 0, 0}, [3]float64{}, nil
}
func (publicEphemerisEngine) Coverage(target astro.Body) (float64, float64, bool) {
return 2400000, 2500000, true
}
var _ astro.Engine = publicEphemerisEngine{}
var _ astro.Engine = (*spk.File)(nil)
var _ func(float64, *astro.Instance) basic.LunarEclipseResult = basic.LunarEclipseWithInstance
var _ func(float64, *astro.Instance) float64 = basic.MoonPhaseWithInstance
var _ func(float64, *astro.Instance) float64 = basic.MercuryApparentLoWithInstance
var _ func(float64, *astro.Instance) float64 = basic.HSunTrueLoWithInstance
var _ func(int, int, *astro.Instance) float64 = basic.GetJQTimeWithInstance
func TestP3PublicInstanceConstruction(t *testing.T) {
for _, model := range []astro.EphemerisModel{astro.EphemerisLegacy, astro.EphemerisSemianalytic} {
inst := mustInstance(t, model)
if inst.Model() != model {
t.Fatalf("model constructor lost identity: %v", inst.Model())
}
if result := basic.LunarEclipseWithInstance(basic.JDCalc(2022, 11, 8), inst); !result.HasTotal {
t.Errorf("public model instance lost eclipse: %+v", result)
}
}
inst := astro.NewInstance(publicEphemerisEngine{})
position, _, err := inst.State(astro.BodySun, astro.BodyEarth, 2451545)
if err != nil || position[0] != 149597870.7 || inst.Model() != astro.EphemerisCustom {
t.Fatalf("custom instance: %v, %v", position, err)
}
if distance := basic.EarthAwayNWithInstance(2451545, -1, inst); math.Abs(distance-1) > 1e-9 {
t.Errorf("public instance could not reach basic: %v", distance)
}
_, _, _, err = inst.Apparent(astro.BodySun, 2451545)
if !errors.Is(err, astro.ErrEphemerisUnsupportedApparent) {
t.Errorf("public error identity was lost: %v", err)
}
if longitude := basic.HSunTrueLoWithInstance(2451545, astro.NewInstance(nil)); !math.IsNaN(longitude) {
t.Errorf("empty custom engine fell back: %v", longitude)
}
}
func TestNewModelInstanceRejectsNonBuiltin(t *testing.T) {
for _, model := range []astro.EphemerisModel{astro.EphemerisCustom, astro.EphemerisModel(42)} {
if inst, err := astro.NewModelInstance(model); inst != nil || !errors.Is(err, astro.ErrUnknownModel) {
t.Errorf("model %v: inst=%v err=%v", model, inst, err)
}
}
}
func TestP3PublicLunarDateQuery(t *testing.T) {
inst := mustInstance(t, astro.EphemerisSemianalytic)
date := time.Date(2022, 11, 8, 12, 0, 0, 0, time.UTC)
info, ok := eclipse.LunarEclipseOnDateWithInstance(date, inst)
if !ok || !info.HasTotal {
t.Errorf("public instance did not reach eclipse query: %+v", info)
}
}