-
Notifications
You must be signed in to change notification settings - Fork 1
/
western_test.go
158 lines (129 loc) · 3.41 KB
/
western_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
package gozodiacs
import (
"fmt"
"testing"
"time"
)
func TestGetWesternZodiacSignPicsesCusp(t *testing.T) {
testTime, err := time.Parse(ZodiacDayDateFormat, "1982-Mar-20")
if err != nil {
t.Fatal(err)
}
signs := GetWesternZodiacsForDate(testTime)
if signs[0] != Pisces || signs[1] != Aries {
t.Fatal(signs)
}
}
func TestGetWesternZodiacSignListCorrectSizeAndNoEmptyStrings(t *testing.T) {
signs := GetAllWesternZodiacSigns()
if len(signs) != 12 {
t.Fatal(signs)
}
for _, sign := range signs {
if sign.String() == "" || sign.UnicodeCharacterAsString() == "" {
t.Fatalf("%v -> %s -> %s", sign, sign.String(), sign.UnicodeCharacterAsString())
}
}
}
func TestGetWesternZodiacStrings(t *testing.T) {
var tests = []struct {
expected string
sign WesternZodiacSign
}{
{"Aries", Aries},
{"Taurus", Taurus},
{"Gemini", Gemini},
{"Cancer", Cancer},
{"Leo", Leo},
{"Virgo", Virgo},
{"Libra", Libra},
{"Scorpio", Scorpio},
{"Sagittarius", Sagittarius},
{"Capricorn", Capricorn},
{"Aquarius", Aquarius},
{"Pisces", Pisces},
}
for _, tt := range tests {
testname := fmt.Sprintf("%s,%v", tt.expected, tt.sign)
t.Run(
testname,
func(t *testing.T) {
if tt.expected != tt.sign.String() {
t.Fatalf("%v != %v", tt.expected, tt.sign.String())
}
},
)
}
}
func TestGetWesternZodiacsAsUnicodeCharacterAsStrings(t *testing.T) {
var tests = []struct {
expected string
sign WesternZodiacSign
}{
{"♈︎", Aries},
{"♉︎", Taurus},
{"♊︎", Gemini},
{"♋︎", Cancer},
{"♌︎", Leo},
{"♍︎", Virgo},
{"♎︎", Libra},
{"♏︎", Scorpio},
{"♐︎", Sagittarius},
{"♑︎", Capricorn},
{"♒︎", Aquarius},
{"♓︎", Pisces},
}
for _, tt := range tests {
testname := fmt.Sprintf("%s,%v", tt.expected, tt.sign)
t.Run(
testname,
func(t *testing.T) {
if tt.expected != tt.sign.UnicodeCharacterAsString() {
t.Fatalf("%v != %v", tt.expected, tt.sign.UnicodeCharacterAsString())
}
},
)
}
}
func TestGetWesternZodiacSignsOverYearRange(t *testing.T) {
min := 1900
bound := 2000
max := min + bound
// First *waves sonic screwdriver* we start in the past..
tardis := time.Date(min, time.January, 0, 0, 0, 0, 0, time.Local)
// ...Then we count the years (as usual)
for tardis.UTC().Year() < max {
// There are rules.
dateString := tardis.Format(ZodiacDayDateFormat)
// LoL
testTime, err := time.Parse(ZodiacDayDateFormat, dateString)
// Oops.
if err != nil {
t.Fatal(err)
}
// ... and look at the planets spin around the sun ...
signs := GetWesternZodiacsForDate(testTime)
// Bad news. If this happens, you have to go back and try to save the past. Its all up to you.
if len(signs) == 0 {
panic("no western zodiac for given date of " + testTime.String() + ", and thats wierd.")
}
// *pulls big lever*
tardis = tardis.AddDate(0, 0, 1)
}
}
/* Solar drift says this should actually fail? How Accurate is the Western Zodiac, Cosmologically speaking? */
func BenchmarkGetWesternZodiacSignsOverYearRange(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)
}
signs := GetWesternZodiacsForDate(testTime)
if len(signs) != 2 || signs[0] != Pisces || signs[1] != Aries {
b.Fatal(err)
}
}
}