-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday_test.go
123 lines (108 loc) · 2.99 KB
/
day_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
package almanac
import (
"testing"
)
func TestNewDay(t *testing.T) {
var time = NewTime(-1000, 12, 30, 14, 0, 0)
var day = NewDay(time)
if day.MonthFirstWeek != 6 ||
day.MonthDaysCount != 31 ||
day.GetZodiacName() != "摩羯座" ||
day.GetChineseZodiacName() != "龙" ||
day.GetGanName() != "庚" ||
day.GetZhiName() != "辰" ||
day.Mark != "康王" {
t.Error(day)
}
time = NewTime(1582, 10, 4, 14, 0, 0)
day = NewDay(time)
if day.MonthFirstWeek != 1 ||
day.MonthDaysCount != 21 ||
day.GetZodiacName() != "天秤座" ||
day.GetChineseZodiacName() != "马" ||
day.GetGanName() != "壬" ||
day.GetZhiName() != "午" ||
day.Mark != "神宗" {
t.Error(day)
}
time = NewTime(1582, 10, 22, 14, 0, 0)
day = NewDay(time)
if day.MonthFirstWeek != 1 ||
day.MonthDaysCount != 21 ||
day.GetZodiacName() != "天蝎座" ||
day.GetChineseZodiacName() != "马" ||
day.GetGanName() != "壬" ||
day.GetZhiName() != "午" ||
day.Mark != "神宗" {
t.Error(day)
}
time = NewTime(2022, 8, 5, 14, 0, 0)
day = NewDay(time)
if day.MonthFirstWeek != 1 ||
day.MonthDaysCount != 31 ||
day.GetZodiacName() != "狮子座" ||
day.GetChineseZodiacName() != "虎" ||
day.GetGanName() != "壬" ||
day.GetZhiName() != "寅" ||
day.Mark != "中国" {
t.Error(day)
}
time = NewTime(9999, 12, 31, 14, 0, 0)
day = NewDay(time)
if day.MonthFirstWeek != 3 ||
day.MonthDaysCount != 31 ||
day.GetZodiacName() != "摩羯座" ||
day.GetChineseZodiacName() != "猪" ||
day.GetGanName() != "己" ||
day.GetZhiName() != "亥" ||
day.Mark != "中国" {
t.Error(day)
}
}
// 测试回历
func TestCalcHijri(t *testing.T) {
var time = NewTime(-1000, 12, 30, 14, 0, 0)
var day = NewDay(time)
var e = Hijri{-1671, 8, 27}
if day.Hijri != e {
t.Error(time, "calcHijri error:", day.Hijri, ", But expect:", e)
}
time = NewTime(1582, 10, 4, 14, 0, 0)
day = NewDay(time)
e = Hijri{990, 9, 16}
if day.Hijri != e {
t.Error(time, "calcHijri error:", day.Hijri, ", But expect:", e)
}
time = NewTime(1582, 10, 22, 14, 0, 0)
day = NewDay(time)
e = Hijri{990, 9, 24}
if day.Hijri != e {
t.Error(time, "calcHijri error:", day.Hijri, ", But expect:", e)
}
time = NewTime(2022, 7, 29, 14, 0, 0)
day = NewDay(time)
e = Hijri{1443, 12, 29}
if day.Hijri != e {
t.Error(time, "calcHijri error:", day.Hijri, ", But expect:", e)
}
time = NewTime(9999, 12, 31, 14, 0, 0)
day = NewDay(time)
e = Hijri{9666, 4, 2}
if day.Hijri != e {
t.Error(time, "calcHijri error:", day.Hijri, ", But expect:", e)
}
}
func TestWeekIndex(t *testing.T) {
var day = NewDay(NewTime(2022, 1, 1, 0, 0, 0))
if day.WeekIndexInYear != 0 || day.WeekIndexInMonth != 0 {
t.Error(day.Time, " Week Index error:")
}
day = NewDay(NewTime(2022, 8, 10, 0, 0, 0))
if day.WeekIndexInYear != 32 || day.WeekIndexInMonth != 1 {
t.Error(day.Time, " Week Index error:")
}
day = NewDay(NewTime(2022, 12, 31, 0, 0, 0))
if day.WeekIndexInYear != 52 || day.WeekIndexInMonth != 4 {
t.Error(day.Time, " Week Index error:")
}
}