-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathage_test.go
35 lines (28 loc) · 943 Bytes
/
age_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
package identity
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
// 测试指定时间之间年龄
func TestAgeAt(t *testing.T) {
b := time.Date(2016, 1, 1 ,0 ,0 ,0 , 0, time.UTC)
n := time.Date(2019, 1, 1 ,0 ,0 ,0 , 0, time.UTC)
assert.Equal(t, AgeAt(b, n), 3)
b = time.Date(2016, 2, 3 ,0 ,0 ,0 , 0, time.UTC)
n = time.Date(2019, 2, 2 ,0 ,0 ,0 , 0, time.UTC)
assert.Equal(t, AgeAt(b, n), 2)
b = time.Date(2016, 2, 3 ,0 ,0 ,0 , 0, time.UTC)
n = time.Date(2019, 2, 3 ,0 ,0 ,0 , 0, time.UTC)
assert.Equal(t, AgeAt(b, n), 3)
}
// 测试年份是不是闰年
func TestIsLeapYear(t *testing.T) {
//loc, _ := time.LoadLocation("Asia/Shanghai")
d := time.Date(2016, 1, 1 ,0 ,0 ,0 , 0, time.UTC)
assert.Equal(t, IsLeapYear(d), true)
d = time.Date(2015, 1, 1 ,0 ,0 ,0 , 0, time.UTC)
assert.Equal(t, IsLeapYear(d), false)
d = time.Date(1986, 2, 1 ,0 ,0 ,0 , 0, time.UTC)
assert.Equal(t, IsLeapYear(d), false)
}