-
Notifications
You must be signed in to change notification settings - Fork 1
/
chinese_test.go
83 lines (59 loc) · 1.5 KB
/
chinese_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
package gozodiacs
import (
"testing"
"time"
"fmt"
)
func TestGetChineseZodiacSign(t *testing.T) {
testTime, err := time.Parse(ZodiacDayDateFormat, "1982-Mar-20")
if err != nil {
t.Fatal(err)
}
sign := GetChineseZodiacSign(testTime)
if sign != Dog {
t.Fatalf("%v", sign)
}
}
func TestGetChineseZodiacSignsAreNotEmptyStrings(t *testing.T) {
signs := GetAllChineseZodiacSigns()
if len(signs) != 12 {
panic("wrong number of chinese zodiac signs")
}
for _, sign := range signs {
if sign.String() == "" {
t.Fatalf("%v -> %s", sign, sign.String())
}
}
}
/* Scan years and expect a sign. */
func TestGetChineseZodiacSignsOverYearRange(t *testing.T) {
min := 1900
bound := 2000
max := min + bound
tardis := time.Date(min, time.January, 0, 0, 0, 0, 0, time.Local)
for tardis.UTC().Year() < max {
dateString := tardis.Format(ZodiacDayDateFormat)
testTime, err := time.Parse(ZodiacDayDateFormat, dateString)
if err != nil {
t.Fatal(err)
}
_ = GetChineseZodiacSign(testTime)
tardis = tardis.AddDate(0, 0, 1)
}
}
/* See README: NASA says solar drift should make this fail, eventually. */
func BenchmarkGetChineseZodiacSignsOverYearRange(b *testing.B) {
bound := 5000
currentYear := time.Now().Year()
for y := 1900; y < currentYear+bound; y++ {
dateString := fmt.Sprintf("%d-Mar-20", y)
testTime, err := time.Parse(ZodiacDayDateFormat, dateString)
if err != nil {
b.Fatal(err)
}
sign := GetChineseZodiacSign(testTime)
if sign != Dog {
b.Fatal(sign)
}
}
}