-
Notifications
You must be signed in to change notification settings - Fork 0
/
qreki_test.go
189 lines (172 loc) · 6.44 KB
/
qreki_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package qreki
import (
"reflect"
"testing"
"time"
)
func TestQreki(t *testing.T) {
testcases := []struct {
in time.Time
out Qreki
}{
{time.Date(2002, 6, 3, 0, 0, 0, 0, JST), Qreki{2002, 4, 23, false, "友引"}},
// https://github.com/shogo82148/go-qreki/blob/33f500c22366f2c5796db35c29693263a909c473/qreki_test.go
{time.Date(2015, 12, 31, 0, 0, 0, 0, JST), Qreki{2015, 11, 21, false, "先勝"}},
{time.Date(2016, 1, 1, 0, 0, 0, 0, JST), Qreki{2015, 11, 22, false, "友引"}},
{time.Date(2016, 2, 7, 0, 0, 0, 0, JST), Qreki{2015, 12, 29, false, "仏滅"}},
{time.Date(2016, 2, 8, 0, 0, 0, 0, JST), Qreki{2016, 1, 1, false, "先勝"}},
{time.Date(2016, 3, 8, 0, 0, 0, 0, JST), Qreki{2016, 1, 30, false, "赤口"}},
{time.Date(2016, 3, 9, 0, 0, 0, 0, JST), Qreki{2016, 2, 1, false, "友引"}},
{time.Date(2016, 4, 6, 0, 0, 0, 0, JST), Qreki{2016, 2, 29, false, "赤口"}},
{time.Date(2016, 4, 7, 0, 0, 0, 0, JST), Qreki{2016, 3, 1, false, "先負"}},
{time.Date(2016, 5, 6, 0, 0, 0, 0, JST), Qreki{2016, 3, 30, false, "友引"}},
{time.Date(2016, 5, 7, 0, 0, 0, 0, JST), Qreki{2016, 4, 1, false, "仏滅"}},
{time.Date(2016, 6, 4, 0, 0, 0, 0, JST), Qreki{2016, 4, 29, false, "友引"}},
{time.Date(2016, 6, 5, 0, 0, 0, 0, JST), Qreki{2016, 5, 1, false, "大安"}},
{time.Date(2016, 7, 3, 0, 0, 0, 0, JST), Qreki{2016, 5, 29, false, "先負"}},
{time.Date(2016, 7, 4, 0, 0, 0, 0, JST), Qreki{2016, 6, 1, false, "赤口"}},
{time.Date(2016, 8, 2, 0, 0, 0, 0, JST), Qreki{2016, 6, 30, false, "大安"}},
{time.Date(2016, 8, 3, 0, 0, 0, 0, JST), Qreki{2016, 7, 1, false, "先勝"}},
{time.Date(2016, 8, 31, 0, 0, 0, 0, JST), Qreki{2016, 7, 29, false, "大安"}},
{time.Date(2016, 9, 1, 0, 0, 0, 0, JST), Qreki{2016, 8, 1, false, "友引"}},
{time.Date(2016, 9, 30, 0, 0, 0, 0, JST), Qreki{2016, 8, 30, false, "先勝"}},
{time.Date(2016, 10, 1, 0, 0, 0, 0, JST), Qreki{2016, 9, 1, false, "先負"}},
{time.Date(2016, 10, 30, 0, 0, 0, 0, JST), Qreki{2016, 9, 30, false, "友引"}},
{time.Date(2016, 10, 31, 0, 0, 0, 0, JST), Qreki{2016, 10, 1, false, "仏滅"}},
{time.Date(2016, 11, 28, 0, 0, 0, 0, JST), Qreki{2016, 10, 29, false, "友引"}},
{time.Date(2016, 11, 29, 0, 0, 0, 0, JST), Qreki{2016, 11, 1, false, "大安"}},
{time.Date(2016, 12, 28, 0, 0, 0, 0, JST), Qreki{2016, 11, 30, false, "仏滅"}},
{time.Date(2016, 12, 29, 0, 0, 0, 0, JST), Qreki{2016, 12, 1, false, "赤口"}},
{time.Date(2017, 1, 1, 0, 0, 0, 0, JST), Qreki{2016, 12, 4, false, "先負"}},
{time.Date(2017, 1, 27, 0, 0, 0, 0, JST), Qreki{2016, 12, 30, false, "大安"}},
{time.Date(2017, 1, 28, 0, 0, 0, 0, JST), Qreki{2017, 1, 1, false, "先勝"}},
{time.Date(2017, 6, 23, 0, 0, 0, 0, JST), Qreki{2017, 5, 29, false, "先負"}},
{time.Date(2017, 6, 24, 0, 0, 0, 0, JST), Qreki{2017, 5, 1, true, "大安"}},
{time.Date(2017, 7, 22, 0, 0, 0, 0, JST), Qreki{2017, 5, 29, true, "先負"}},
{time.Date(2017, 7, 23, 0, 0, 0, 0, JST), Qreki{2017, 6, 1, false, "赤口"}},
{time.Date(2033, 12, 21, 0, 0, 0, 0, JST), Qreki{2033, 11, 30, false, "仏滅"}},
{time.Date(2033, 12, 22, 0, 0, 0, 0, JST), Qreki{2033, 11, 1, true, "大安"}},
{time.Date(2034, 1, 19, 0, 0, 0, 0, JST), Qreki{2033, 11, 29, true, "先負"}},
{time.Date(2034, 1, 20, 0, 0, 0, 0, JST), Qreki{2033, 12, 1, false, "赤口"}},
{time.Date(2020, 1, 1, 0, 0, 0, 0, JST), Qreki{2019, 12, 7, false, "赤口"}},
{time.Date(2030, 1, 1, 0, 0, 0, 0, JST), Qreki{2029, 11, 28, false, "友引"}},
}
for _, tc := range testcases {
got := NewQreki(ToJulian(tc.in))
if !reflect.DeepEqual(got, tc.out) {
t.Errorf("%v: got %v, want %v", tc.in, got, tc.out)
}
}
}
func TestToJulian(t *testing.T) {
testcases := []struct {
in time.Time
out float64
}{
{time.Date(2002, 6, 3, 0, 0, 0, 0, JST), 2452428.0},
}
for _, tc := range testcases {
got := ToJulian(tc.in)
if !reflect.DeepEqual(got, tc.out) {
t.Errorf("%v: got %v, want %v", tc.in, got, tc.out)
}
}
}
// TODO Available to get expected result but DeepEqual doesn't return true.
// func TestToTime(t *testing.T) {
// testcases := []struct {
// in float64
// out time.Time
// }{
// {2452428.0, time.Date(2002, 6, 3, 0, 0, 0, 0, JST)},
// }
//
// for _, tc := range testcases {
// got := ToTime(tc.in)
// if !reflect.DeepEqual(got, tc.out) {
// t.Errorf("%v: got %v, want %v", tc.in, got, tc.out)
// }
// }
// }
func TestNormalizeAngle(t *testing.T) {
testcases := []struct {
in float64
out float64
}{
{31557.0*2451545.0 + 161.0, 86.0},
{-10993.857868377594 + 303.8119083007812, 109.95403992318643},
// FYI https://go.dev/src/math/sin.go
// Results may be meaningless for x > 2**49 = 5.6e14.
// Golang might give the different value with sin/cos between other languages.
// [Go 言語の math.Sin は計算結果がおかしいことがある - Qiita](https://qiita.com/Nabetani/items/2dd5e2351b6d2f8ed53f)
// {-10993.857868377594 + 303.8119083007812, 109.95403992318825},
}
for _, tc := range testcases {
got := NormalizeAngle(tc.in)
if !reflect.DeepEqual(got, tc.out) {
t.Errorf("%v: got %v, want %v", tc.in, got, tc.out)
}
}
}
func TestCalcSolarLongitude(t *testing.T) {
testcases := []struct {
in float64
out float64
}{
{2452428.0, 109.95403992318643},
// {2452428.0, 109.95403992318825}, // with other languages
}
for _, tc := range testcases {
got := CalcSolarLongitude(tc.in)
if !reflect.DeepEqual(got, tc.out) {
t.Errorf("%v: got %v, want %v", tc.in, got, tc.out)
}
}
}
func TestCalcMoonLongitude(t *testing.T) {
testcases := []struct {
in float64
out float64
}{
{2452428.0, 233.26846620995252},
}
for _, tc := range testcases {
got := CalcMoonLongitude(tc.in)
if !reflect.DeepEqual(got, tc.out) {
t.Errorf("%v: got %v, want %v", tc.in, got, tc.out)
}
}
}
func TestCalcChuki(t *testing.T) {
type args struct {
julian float64
longitude float64
}
testcases := []struct {
in args
out float64
}{
// {args{2452428.0, 90.0}, 2452354.168240371},
{args{2463952.0, 90.0}, 2463861.675270711},
}
for _, tc := range testcases {
got := CalcChuki(tc.in.julian, tc.in.longitude)
if !reflect.DeepEqual(got, tc.out) {
t.Errorf("%v: got %v, want %v", tc.in, got, tc.out)
}
}
}
func TestCalcNewMoon(t *testing.T) {
testcases := []struct {
in float64
out float64
}{
{2452428.0, 2452406.824613828},
}
for _, tc := range testcases {
got := CalcNewMoon(tc.in)
if !reflect.DeepEqual(got, tc.out) {
t.Errorf("%v: got %v, want %v", tc.in, got, tc.out)
}
}
}