-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlunar_test.go
More file actions
124 lines (118 loc) · 4.14 KB
/
Copy pathlunar_test.go
File metadata and controls
124 lines (118 loc) · 4.14 KB
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
package calendar
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestGetLeapMonth(t *testing.T) {
assert := assert.New(t)
assert.Equal(0, GetLeapMonth(2015))
assert.Equal(0, GetLeapMonth(2016))
assert.Equal(6, GetLeapMonth(2017))
assert.Equal(0, GetLeapMonth(2018))
assert.Equal(0, GetLeapMonth(2019))
assert.Equal(4, GetLeapMonth(2020))
assert.Equal(0, GetLeapMonth(2021))
assert.Equal(0, GetLeapMonth(2022))
assert.Equal(2, GetLeapMonth(2023))
assert.Equal(0, GetLeapMonth(2024))
assert.Equal(6, GetLeapMonth(2025))
}
func TestLunarConv(t *testing.T) {
assert := assert.New(t)
tests := []struct {
solar time.Time
lunar time.Time
leap bool
}{
{
solar: time.Date(2015, 1, 14, 12, 30, 0, 0, Paris),
lunar: time.Date(2014, 11, 24, 12, 30, 0, 0, Paris),
leap: false,
},
{
solar: time.Date(2015, 2, 19, 12, 30, 0, 0, Paris),
lunar: time.Date(2015, 1, 1, 12, 30, 0, 0, Paris),
leap: false,
},
{
solar: time.Date(2015, 4, 14, 12, 30, 0, 0, Paris),
lunar: time.Date(2015, 2, 26, 12, 30, 0, 0, Paris),
leap: false,
},
{
solar: time.Date(2020, 1, 14, 12, 30, 0, 0, Paris),
lunar: time.Date(2019, 12, 20, 12, 30, 0, 0, Paris),
leap: false,
},
{
solar: time.Date(2020, 1, 25, 12, 30, 0, 0, Paris),
lunar: time.Date(2020, 1, 1, 12, 30, 0, 0, Paris),
leap: false,
},
{
solar: time.Date(2020, 5, 14, 12, 30, 0, 0, Paris),
lunar: time.Date(2020, 4, 22, 12, 30, 0, 0, Paris),
leap: false,
},
{
solar: time.Date(2020, 6, 13, 12, 30, 0, 0, Paris),
lunar: time.Date(2020, 4, 22, 12, 30, 0, 0, Paris),
leap: true,
},
{
solar: time.Date(2025, 1, 14, 12, 30, 0, 0, Paris),
lunar: time.Date(2024, 12, 15, 12, 30, 0, 0, Paris),
leap: false,
},
{
solar: time.Date(2025, 1, 29, 12, 30, 0, 0, Paris),
lunar: time.Date(2025, 1, 1, 12, 30, 0, 0, Paris),
leap: false,
},
{
solar: time.Date(2025, 7, 15, 12, 30, 0, 0, Paris),
lunar: time.Date(2025, 6, 21, 12, 30, 0, 0, Paris),
leap: false,
},
{
solar: time.Date(2025, 8, 14, 12, 30, 0, 0, Paris),
lunar: time.Date(2025, 6, 21, 12, 30, 0, 0, Paris),
leap: true,
},
}
for _, test := range tests {
toLunarTime, toLunarLeap := GregorianToLunisolar(test.solar)
assert.Equal(test.lunar, toLunarTime)
assert.Equal(test.leap, toLunarLeap)
assert.Equal(test.solar, LunisolarToGregorian(test.lunar, test.leap))
}
}
func TestGetLunarMonthDays(t *testing.T) {
assert := assert.New(t)
assert.Equal(29, GetLunisolarMonthDays(2020, time.Month(1), false))
assert.Equal(30, GetLunisolarMonthDays(2020, time.Month(2), false))
assert.Equal(30, GetLunisolarMonthDays(2020, time.Month(3), false))
assert.Equal(30, GetLunisolarMonthDays(2020, time.Month(4), false))
assert.Equal(29, GetLunisolarMonthDays(2020, time.Month(4), true))
assert.Equal(30, GetLunisolarMonthDays(2020, time.Month(5), false))
assert.Equal(29, GetLunisolarMonthDays(2020, time.Month(6), false))
assert.Equal(29, GetLunisolarMonthDays(2020, time.Month(7), false))
assert.Equal(30, GetLunisolarMonthDays(2020, time.Month(8), false))
assert.Equal(29, GetLunisolarMonthDays(2020, time.Month(9), false))
assert.Equal(30, GetLunisolarMonthDays(2020, time.Month(10), false))
assert.Equal(29, GetLunisolarMonthDays(2020, time.Month(11), false))
assert.Equal(30, GetLunisolarMonthDays(2020, time.Month(12), false))
assert.Equal(29, GetLunisolarMonthDays(2021, time.Month(1), false))
assert.Equal(30, GetLunisolarMonthDays(2021, time.Month(2), false))
assert.Equal(30, GetLunisolarMonthDays(2021, time.Month(3), false))
assert.Equal(29, GetLunisolarMonthDays(2021, time.Month(4), false))
assert.Equal(30, GetLunisolarMonthDays(2021, time.Month(5), false))
assert.Equal(29, GetLunisolarMonthDays(2021, time.Month(6), false))
assert.Equal(30, GetLunisolarMonthDays(2021, time.Month(7), false))
assert.Equal(29, GetLunisolarMonthDays(2021, time.Month(8), false))
assert.Equal(30, GetLunisolarMonthDays(2021, time.Month(9), false))
assert.Equal(29, GetLunisolarMonthDays(2021, time.Month(10), false))
assert.Equal(30, GetLunisolarMonthDays(2021, time.Month(11), false))
assert.Equal(29, GetLunisolarMonthDays(2021, time.Month(12), false))
}