-
Notifications
You must be signed in to change notification settings - Fork 3
/
operators_test.go
87 lines (70 loc) · 1.67 KB
/
operators_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
package tinytime
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestAfter(t *testing.T) {
tt := TinyTime{unix: 1585750374}
tu := TinyTime{unix: 1585750374}
assert.False(t, tt.After(tu))
tt = TinyTime{unix: 1585750375}
tu = TinyTime{unix: 1585750376}
assert.False(t, tt.After(tu))
tt = TinyTime{unix: 1585750374}
tu = TinyTime{unix: 1585750373}
assert.True(t, tt.After(tu))
}
func TestBefore(t *testing.T) {
tt := TinyTime{unix: 1585750374}
tu := TinyTime{unix: 1585750374}
assert.False(t, tt.Before(tu))
tt = TinyTime{unix: 1585750374}
tu = TinyTime{unix: 1585750373}
assert.False(t, tt.Before(tu))
tt = TinyTime{unix: 1585750374}
tu = TinyTime{unix: 1585750375}
assert.True(t, tt.Before(tu))
}
func TestAdd(t *testing.T) {
tt := TinyTime{unix: 1583020800}
assert.Equal(t,
TinyTime{unix: 1583107200},
tt.Add(time.Hour*24),
)
tt = TinyTime{unix: 1583107200}
assert.Equal(t,
TinyTime{unix: 1583020800},
tt.Add(-time.Hour*24),
)
}
func TestAddDate(t *testing.T) {
tt := TinyTime{unix: 1583020800}
assert.Equal(t,
TinyTime{unix: 1583107200},
tt.AddDate(0, 0, 1),
)
tt = TinyTime{unix: 1583107200}
assert.Equal(t,
TinyTime{unix: 1583020800},
tt.AddDate(0, 0, -1),
)
}
func TestEqual(t *testing.T) {
tt := New(1585750374)
assert.True(t, tt.Equal(tt))
tt = New(1583107200)
tu := New(1583020800)
assert.False(t, tt.Equal(tu))
}
func TestSub(t *testing.T) {
tt := New(1583107200)
tu := New(1583020800)
assert.Equal(t, time.Hour*24, tt.Sub(tu))
tt = New(1585750374)
tu = New(1585750374)
assert.Equal(t, time.Duration(0), tt.Sub(tu))
tt = New(1583020800)
tu = New(1583107200)
assert.Equal(t, -time.Hour*24, tt.Sub(tu))
}