-
Notifications
You must be signed in to change notification settings - Fork 4
/
time_test.go
58 lines (50 loc) · 1.25 KB
/
time_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
package goutil
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestZodiac(t *testing.T) {
cases := []struct{ ts, zodiac string }{
{"20180924", "天秤"},
{"19830601", "双子"},
{"19840304", "双鱼"},
}
for _, c := range cases {
tm, err := time.Parse("20060102", c.ts)
if err != nil {
t.Error(err)
}
assert.Equal(t, GetZodiacForTime(tm), c.zodiac, "")
}
}
func TestCnZodiacGanZhi(t *testing.T) {
cases := []struct{ ts, zodiac, gan, zhi, emoji string }{
{"2018", "狗", "戌", "戊", "🐕"},
{"1983", "猪", "亥", "癸", "🐖"},
{"2015", "羊", "未", "乙", "🐐"},
}
for _, c := range cases {
tm, err := time.Parse("2006", c.ts)
if err != nil {
t.Error(err)
}
assert.Equal(t, GetCnZodiacForTime(tm), c.zodiac, "")
assert.Equal(t, GetGanForTime(tm), c.gan, "")
assert.Equal(t, GetZhiForTime(tm), c.zhi, "")
assert.Equal(t, GetCnZodiacEmojiForTime(tm), c.emoji, "")
}
}
func TestTimeStr(t *testing.T) {
cases := []struct {
timestamp int64
expected string
}{
{1577836800, "20200101000000"}, // 2020-01-01 00:00:00 UTC
}
for _, c := range cases {
result := TimeStr(c.timestamp)
assert.Equal(t, c.expected, result, "TimeStr(%d) = %s; want %s",
c.timestamp, result, c.expected)
}
}