11package basic
22
33import (
4- "github.com/starainrt/astro/tools"
54 "fmt"
65 "math"
76 "testing"
87 "time"
8+
9+ "github.com/starainrt/astro/tools"
910)
1011
1112func Benchmark_MoonRiseBench (b * testing.B ) {
@@ -492,11 +493,11 @@ var moonRiseSetTestData = []MoonRiseSetTestCase{
492493 {2024 , 2 , 29.0 , 31.2357 , 30.0444 , 2.0 , 1 , 100 , 2460370.429845 , 2460369.865380 },
493494 {2024 , 2 , 29.0 , 31.2357 , 30.0444 , 2.0 , 1 , 1000 , 2460370.428616 , 2460369.866552 },
494495 {2025 , 7 , 4.0 , 31.2357 , 30.0444 , 2.0 , 0 , 0 , 2460861.065509 , - 3.000000 },
495- {2025 , 7 , 4.0 , 31.2357 , 30.0444 , 2.0 , 0 , 100 , 2460861.064944 , - 3.000000 },
496- {2025 , 7 , 4.0 , 31.2357 , 30.0444 , 2.0 , 0 , 1000 , 2460861.063725 , - 3.000000 },
497- {2025 , 7 , 4.0 , 31.2357 , 30.0444 , 2.0 , 1 , 0 , 2460861.062582 , - 3.000000 },
498- {2025 , 7 , 4.0 , 31.2357 , 30.0444 , 2.0 , 1 , 100 , 2460861.062019 , - 3.000000 },
499- {2025 , 7 , 4.0 , 31.2357 , 30.0444 , 2.0 , 1 , 1000 , 2460861.060803 , - 3.000000 },
496+ {2025 , 7 , 4.0 , 31.2357 , 30.0444 , 2.0 , 0 , 100 , 2460861.064944 , 2460860.500441 },
497+ {2025 , 7 , 4.0 , 31.2357 , 30.0444 , 2.0 , 0 , 1000 , 2460861.063725 , 2460860.501606 },
498+ {2025 , 7 , 4.0 , 31.2357 , 30.0444 , 2.0 , 1 , 0 , 2460861.062582 , 2460860.502699 },
499+ {2025 , 7 , 4.0 , 31.2357 , 30.0444 , 2.0 , 1 , 100 , 2460861.062019 , 2460860.503237 },
500+ {2025 , 7 , 4.0 , 31.2357 , 30.0444 , 2.0 , 1 , 1000 , 2460861.060803 , 2460860.504400 },
500501 {2023 , 1 , 15.0 , - 43.1729 , - 22.9068 , - 3.0 , 0 , 0 , - 3.000000 , 2459960.019905 },
501502 {2023 , 1 , 15.0 , - 43.1729 , - 22.9068 , - 3.0 , 0 , 100 , - 3.000000 , 2459960.020416 },
502503 {2023 , 1 , 15.0 , - 43.1729 , - 22.9068 , - 3.0 , 0 , 1000 , - 3.000000 , 2459960.021522 },
@@ -619,10 +620,10 @@ var moonRiseSetTestData = []MoonRiseSetTestCase{
619620 {2024 , 2 , 29.0 , - 149.9003 , 61.2181 , - 9.0 , 1 , 1000 , 2460369.506308 , 2460369.862264 },
620621 {2025 , 7 , 4.0 , - 149.9003 , 61.2181 , - 9.0 , 0 , 0 , 2460861.205484 , 2460861.493716 },
621622 {2025 , 7 , 4.0 , - 149.9003 , 61.2181 , - 9.0 , 0 , 100 , 2460861.204170 , 2460861.495011 },
622- {2025 , 7 , 4.0 , - 149.9003 , 61.2181 , - 9.0 , 0 , 1000 , 2460861.201358 , 2460861.497780 },
623- {2025 , 7 , 4.0 , - 149.9003 , 61.2181 , - 9.0 , 1 , 0 , 2460861.198757 , - 3.000000 },
624- {2025 , 7 , 4.0 , - 149.9003 , 61.2181 , - 9.0 , 1 , 100 , 2460861.197484 , - 3.000000 },
625- {2025 , 7 , 4.0 , - 149.9003 , 61.2181 , - 9.0 , 1 , 1000 , 2460861.194755 , - 3.000000 },
623+ {2025 , 7 , 4.0 , - 149.9003 , 61.2181 , - 9.0 , 0 , 1000 , 2460861.201358 , 2460860.500309 },
624+ {2025 , 7 , 4.0 , - 149.9003 , 61.2181 , - 9.0 , 1 , 0 , 2460861.198757 , 2460860.502500 },
625+ {2025 , 7 , 4.0 , - 149.9003 , 61.2181 , - 9.0 , 1 , 100 , 2460861.197484 , 2460860.503576 },
626+ {2025 , 7 , 4.0 , - 149.9003 , 61.2181 , - 9.0 , 1 , 1000 , 2460861.194755 , 2460860.505890 },
626627 {2023 , 1 , 15.0 , - 42.6043 , 71.7069 , - 3.0 , 0 , 0 , 2459959.583014 , 2459959.895953 },
627628 {2023 , 1 , 15.0 , - 42.6043 , 71.7069 , - 3.0 , 0 , 100 , 2459959.581157 , 2459959.897741 },
628629 {2023 , 1 , 15.0 , - 42.6043 , 71.7069 , - 3.0 , 0 , 1000 , 2459959.577188 , 2459959.901560 },
@@ -656,8 +657,8 @@ var moonRiseSetTestData = []MoonRiseSetTestCase{
656657 {2024 , 2 , 29.0 , - 42.6043 , 71.7069 , - 3.0 , 0 , 0 , 2460369.510257 , 2460369.739050 },
657658 {2024 , 2 , 29.0 , - 42.6043 , 71.7069 , - 3.0 , 0 , 100 , 2460369.507908 , 2460369.741347 },
658659 {2024 , 2 , 29.0 , - 42.6043 , 71.7069 , - 3.0 , 0 , 1000 , 2460369.502952 , 2460369.746190 },
659- {2024 , 2 , 29.0 , - 42.6043 , 71.7069 , - 3.0 , 1 , 0 , - 3 .000000 , 2460369.750583 },
660- {2024 , 2 , 29.0 , - 42.6043 , 71.7069 , - 3.0 , 1 , 100 , - 3 .000000 , 2460369.752708 },
660+ {2024 , 2 , 29.0 , - 42.6043 , 71.7069 , - 3.0 , 1 , 0 , - 2 .000000 , 2460369.750583 },
661+ {2024 , 2 , 29.0 , - 42.6043 , 71.7069 , - 3.0 , 1 , 100 , - 2 .000000 , 2460369.752708 },
661662 {2024 , 2 , 29.0 , - 42.6043 , 71.7069 , - 3.0 , 1 , 1000 , - 3.000000 , 2460369.757206 },
662663 {2025 , 7 , 4.0 , - 42.6043 , 71.7069 , - 3.0 , 0 , 0 , 2460861.253176 , 2460861.327087 },
663664 {2025 , 7 , 4.0 , - 42.6043 , 71.7069 , - 3.0 , 0 , 100 , 2460861.246829 , 2460861.333396 },
@@ -712,39 +713,41 @@ var moonRiseSetTestData = []MoonRiseSetTestCase{
712713// TestMoonRiseSetRegression 月出月落回归测试
713714func TestMoonRiseSetRegression (t * testing.T ) {
714715 beforeDeltaT := defDeltaTFn
715- SetDeltaTFn (DefaultDeltaT )
716+ SetDeltaTFn (DefaultDeltaTv2 )
716717 defer SetDeltaTFn (beforeDeltaT )
717- const tolerance = 0.000001 // 容差设为1微秒,对于天文计算来说已经足够精确
718+ const tolerance = 0.00011574074
718719
719720 for i , testCase := range moonRiseSetTestData {
720721 julianDay := JDECalc (testCase .Year , testCase .Month , testCase .Day )
721722
722723 // 测试月出时间
724+
723725 actualRise := GetMoonRiseTime (julianDay , testCase .Longitude , testCase .Latitude ,
724726 testCase .TimeZone , testCase .ZenithShift , testCase .Height )
725727
726728 if ! floatEquals (actualRise , testCase .ExpectedRise , tolerance ) {
727729 t .Errorf ("测试用例 %d 月出时间不匹配:\n " +
728730 " 日期: %d-%d-%.1f, 经纬度: (%.4f, %.4f), 时区: %.1f, 天顶修正: %.0f, 海拔: %.0f\n " +
729- " 期望月出: %.6f , 实际月出: %.6f, 差值: %.9f" ,
731+ " 期望月出: %v , 实际月出: %.6f, 差值: %.9f" ,
730732 i , testCase .Year , testCase .Month , testCase .Day ,
731733 testCase .Longitude , testCase .Latitude , testCase .TimeZone ,
732734 testCase .ZenithShift , testCase .Height ,
733- testCase .ExpectedRise , actualRise , math .Abs (actualRise - testCase .ExpectedRise ))
735+ JDE2Date ( testCase .ExpectedRise ) , actualRise , math .Abs (actualRise - testCase .ExpectedRise ))
734736 }
735737
736738 // 测试月落时间
737739 actualSet := GetMoonSetTime (julianDay , testCase .Longitude , testCase .Latitude ,
738740 testCase .TimeZone , testCase .ZenithShift , testCase .Height )
739741
740742 if ! floatEquals (actualSet , testCase .ExpectedSet , tolerance ) {
743+ fmt .Println (JDECalc (testCase .Year , testCase .Month , testCase .Day ))
741744 t .Errorf ("测试用例 %d 月落时间不匹配:\n " +
742745 " 日期: %d-%d-%.1f, 经纬度: (%.4f, %.4f), 时区: %.1f, 天顶修正: %.0f, 海拔: %.0f\n " +
743- " 期望月落: %.6f, 实际月落: %.6f, 差值: %.9f" ,
746+ " 期望月落: %v,% .6f, 实际月落: %v,% .6f , 差值: %.9f" ,
744747 i , testCase .Year , testCase .Month , testCase .Day ,
745748 testCase .Longitude , testCase .Latitude , testCase .TimeZone ,
746749 testCase .ZenithShift , testCase .Height ,
747- testCase .ExpectedSet , actualSet , math .Abs (actualSet - testCase .ExpectedSet ))
750+ JDE2Date ( testCase .ExpectedSet ), testCase . ExpectedSet , JDE2Date ( actualSet ) , actualSet , math .Abs (actualSet - testCase .ExpectedSet ))
748751 }
749752 }
750753
@@ -754,7 +757,7 @@ func TestMoonRiseSetRegression(t *testing.T) {
754757// TestMoonRiseSetSpecialCases 测试特殊情况
755758func TestMoonRiseSetSpecialCases (t * testing.T ) {
756759 beforeDeltaT := defDeltaTFn
757- SetDeltaTFn (DefaultDeltaT )
760+ SetDeltaTFn (DefaultDeltaTv2 )
758761 defer SetDeltaTFn (beforeDeltaT )
759762 testCases := []struct {
760763 name string
0 commit comments