044f2f4381
- 新增半解析、旧模型、自定义与多源堆叠星历实例,提供 Context、Instance、SPK 读取及状态与视位置计算 - 统一太阳、月球和行星实例接口,扩展黄经穿越、留、相位、最近角距、偕日可见、任意高度升落、轨道节点及凌日等天象查询 - 完善日月食、月掩与凌日的月缘剖面、有限盘面接触、站心修正、局地可见性、全球路径和地图输出 - 新增 SVG、GeoJSON、KML 天象输出及凌日、月掩和月缘地形相关缓存与几何求解 - 新增恒星星表导入与查询,支持 CSV、Hipparcos、BSC5、Stellarium 等格式及名称、交叉标识、锥面检索和星等过滤 - 补充 IAU 2006、地球定向、折射消光、大气观测、轨道传播及半解析行星/月球数据支持 - 将默认未来民用时标切换为 TimeScaleLeapHour,更新 2027–2400 农历速查表、中文日期解析和时区边界处理 - 增加事件基线、跨模型回归、几何边界、月缘地形和输出契约测试,完善中英文手册、示例资源、NOTICE 与忽略规则
173 lines
5.2 KiB
Go
173 lines
5.2 KiB
Go
package basic
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestKnownMercuryTransits(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
query time.Time
|
|
greatest time.Time
|
|
}{
|
|
{
|
|
name: "2016 May",
|
|
query: time.Date(2016, 1, 1, 0, 0, 0, 0, time.UTC),
|
|
greatest: time.Date(2016, 5, 9, 14, 57, 0, 0, time.UTC),
|
|
},
|
|
{
|
|
name: "2019 Nov",
|
|
query: time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC),
|
|
greatest: time.Date(2019, 11, 11, 15, 20, 0, 0, time.UTC),
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
result := NextMercuryTransit(Date2JD(tc.query))
|
|
if !result.Valid {
|
|
t.Fatal("expected valid transit")
|
|
}
|
|
got := JD2DateByZone(result.Greatest, time.UTC, false)
|
|
t.Logf("start=%s greatest=%s end=%s min=%.3f sun=%.3f planet=%.3f",
|
|
JD2DateByZone(result.ExternalIngress, time.UTC, false),
|
|
got,
|
|
JD2DateByZone(result.ExternalEgress, time.UTC, false),
|
|
result.MinimumSeparationArcsec,
|
|
result.SunSemidiameterArcsec,
|
|
result.PlanetSemidiameterArcsec,
|
|
)
|
|
if math.Abs(got.Sub(tc.greatest).Seconds()) > 20*60 {
|
|
t.Fatalf("greatest mismatch: got %s want near %s", got, tc.greatest)
|
|
}
|
|
if !result.HasInternal {
|
|
t.Fatalf("expected internal contacts")
|
|
}
|
|
if !(result.ExternalIngress < result.InternalIngress &&
|
|
result.InternalIngress < result.Greatest &&
|
|
result.Greatest < result.InternalEgress &&
|
|
result.InternalEgress < result.ExternalEgress) {
|
|
t.Fatalf("contacts out of order: %+v", result)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestKnownVenusTransits(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
query time.Time
|
|
greatest time.Time
|
|
}{
|
|
{
|
|
name: "2004 Jun",
|
|
query: time.Date(2004, 1, 1, 0, 0, 0, 0, time.UTC),
|
|
greatest: time.Date(2004, 6, 8, 8, 20, 0, 0, time.UTC),
|
|
},
|
|
{
|
|
name: "2012 Jun",
|
|
query: time.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
|
|
greatest: time.Date(2012, 6, 6, 1, 29, 0, 0, time.UTC),
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
result := NextVenusTransit(Date2JD(tc.query))
|
|
if !result.Valid {
|
|
t.Fatal("expected valid transit")
|
|
}
|
|
got := JD2DateByZone(result.Greatest, time.UTC, false)
|
|
t.Logf("start=%s greatest=%s end=%s min=%.3f sun=%.3f planet=%.3f",
|
|
JD2DateByZone(result.ExternalIngress, time.UTC, false),
|
|
got,
|
|
JD2DateByZone(result.ExternalEgress, time.UTC, false),
|
|
result.MinimumSeparationArcsec,
|
|
result.SunSemidiameterArcsec,
|
|
result.PlanetSemidiameterArcsec,
|
|
)
|
|
if math.Abs(got.Sub(tc.greatest).Seconds()) > 20*60 {
|
|
t.Fatalf("greatest mismatch: got %s want near %s", got, tc.greatest)
|
|
}
|
|
if !result.HasInternal {
|
|
t.Fatalf("expected internal contacts")
|
|
}
|
|
if !(result.ExternalIngress < result.InternalIngress &&
|
|
result.InternalIngress < result.Greatest &&
|
|
result.Greatest < result.InternalEgress &&
|
|
result.InternalEgress < result.ExternalEgress) {
|
|
t.Fatalf("contacts out of order: %+v", result)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestTransitSearchSkipsSparseEvents(t *testing.T) {
|
|
mercuryResult := NextMercuryTransit(Date2JD(time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)))
|
|
if !mercuryResult.Valid {
|
|
t.Fatal("expected Mercury transit")
|
|
}
|
|
mercuryGreatest := JD2DateByZone(mercuryResult.Greatest, time.UTC, false)
|
|
if mercuryGreatest.Year() != 2032 || mercuryGreatest.Month() != time.November {
|
|
t.Fatalf("unexpected next Mercury transit: %s", mercuryGreatest)
|
|
}
|
|
|
|
venusResult := NextVenusTransit(Date2JD(time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)))
|
|
if !venusResult.Valid {
|
|
t.Fatal("expected Venus transit")
|
|
}
|
|
venusGreatest := JD2DateByZone(venusResult.Greatest, time.UTC, false)
|
|
if venusGreatest.Year() != 2117 || venusGreatest.Month() != time.December {
|
|
t.Fatalf("unexpected next Venus transit: %s", venusGreatest)
|
|
}
|
|
}
|
|
|
|
func BenchmarkNextMercuryTransitFrom2026(b *testing.B) {
|
|
jd := Date2JD(time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC))
|
|
for i := 0; i < b.N; i++ {
|
|
result := NextMercuryTransit(jd)
|
|
if !result.Valid {
|
|
b.Fatal("expected valid transit")
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkNextVenusTransitFrom2026(b *testing.B) {
|
|
jd := Date2JD(time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC))
|
|
for i := 0; i < b.N; i++ {
|
|
result := NextVenusTransit(jd)
|
|
if !result.Valid {
|
|
b.Fatal("expected valid transit")
|
|
}
|
|
}
|
|
}
|
|
|
|
// 查询时刻落在凌日当天、早于凌甚时,Next/Closest 必须给出当天这次;节点季略早于查询时刻不能把它跳过。
|
|
func TestPlanetTransitSearchFromSameDay(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
find func(float64) PlanetTransitResult
|
|
query float64
|
|
year int
|
|
month int
|
|
day int
|
|
}{
|
|
{"mercury next 1999", NextMercuryTransit, JDCalc(1999, 11, 15), 1999, 11, 15},
|
|
{"mercury closest 1999", ClosestMercuryTransit, JDCalc(1999, 11, 15), 1999, 11, 15},
|
|
{"venus next 2012", NextVenusTransit, JDCalc(2012, 6, 5), 2012, 6, 6},
|
|
{"mercury last after 1999", LastMercuryTransit, JDCalc(1999, 11, 15.95), 1999, 11, 15},
|
|
}
|
|
for _, tc := range cases {
|
|
got := tc.find(tc.query)
|
|
if !got.Valid {
|
|
t.Fatalf("%s: no transit", tc.name)
|
|
}
|
|
date := JD2DateByZone(got.Greatest, time.UTC, false)
|
|
if date.Year() != tc.year || int(date.Month()) != tc.month || date.Day() != tc.day {
|
|
t.Fatalf("%s: greatest %s, want %04d-%02d-%02d", tc.name, date.Format("2006-01-02"), tc.year, tc.month, tc.day)
|
|
}
|
|
}
|
|
}
|