16c62a97d5
- 新增时标、ΔT 模型、质心时间与 UT1 支持 - 改进日月食、月掩、行星事件及路径边界计算 - 完善恒星三维自行与动态距离传播 - 扩展 SVG、GeoJSON、KML 输出与底层距离换算工具 - 整理中英文手册、示例资源及回归测试
74 lines
2.0 KiB
Go
74 lines
2.0 KiB
Go
package eclipse
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"b612.me/astro/basic"
|
|
)
|
|
|
|
func TestEclipseSearchStepDoesNotSkipPotentialCandidates(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
phaseType int
|
|
synodicMonthDays float64
|
|
potential func(float64) bool
|
|
}{
|
|
{
|
|
name: "solar",
|
|
phaseType: 0,
|
|
synodicMonthDays: solarEclipseSynodicMonthDays,
|
|
potential: isPotentialSolarEclipse,
|
|
},
|
|
{
|
|
name: "lunar",
|
|
phaseType: 1,
|
|
synodicMonthDays: lunarEclipseSynodicMonthDays,
|
|
potential: isPotentialLunarEclipse,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
candidates := eclipseSearchTestCandidates(1600, 800, tc.phaseType, tc.synodicMonthDays)
|
|
|
|
for index, candidateTT := range candidates {
|
|
for _, direction := range []int{-1, 1} {
|
|
step := eclipseSearchStep(candidateTT, direction, tc.synodicMonthDays)
|
|
for offset := 1; offset < step; offset++ {
|
|
skippedIndex := index + direction*offset
|
|
if skippedIndex < 0 || skippedIndex >= len(candidates) {
|
|
continue
|
|
}
|
|
if tc.potential(candidates[skippedIndex]) {
|
|
t.Fatalf(
|
|
"%s skip crosses potential candidate: index=%d direction=%d step=%d offset=%d jd=%.8f",
|
|
tc.name,
|
|
index,
|
|
direction,
|
|
step,
|
|
offset,
|
|
candidates[skippedIndex],
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func eclipseSearchTestCandidates(startYear, years, phaseType int, synodicMonthDays float64) []float64 {
|
|
startTT := basic.Date2JD(time.Date(startYear, 1, 1, 0, 0, 0, 0, time.UTC))
|
|
endTT := basic.Date2JD(time.Date(startYear+years, 1, 1, 0, 0, 0, 0, time.UTC))
|
|
candidateTT := basic.CalcMoonSHByJDE(startTT, phaseType)
|
|
candidates := make([]float64, 0, years*13)
|
|
for candidateTT < endTT {
|
|
if candidateTT >= startTT {
|
|
candidates = append(candidates, candidateTT)
|
|
}
|
|
candidateTT = basic.CalcMoonSHByJDE(candidateTT+synodicMonthDays, phaseType)
|
|
}
|
|
return candidates
|
|
}
|