-
Notifications
You must be signed in to change notification settings - Fork 1
/
duration_test.go
53 lines (49 loc) · 1.4 KB
/
duration_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
package simpletime
import (
"testing"
"time"
)
const (
minDuration time.Duration = -1 << 63
maxDuration time.Duration = 1<<63 - 1
)
func TestCompare(t *testing.T) {
tests := []struct {
d1 *SimpleDuration
d2 *SimpleDuration
expected bool
}{
{nil, nil, false},
{NewSimpleDuration(0), nil, false},
{&SimpleDuration{}, &SimpleDuration{}, true},
{NewSimpleDuration(0), NewSimpleDuration(0), true},
{NewSimpleDuration(minDuration), NewSimpleDuration(minDuration), true},
{NewSimpleDuration(maxDuration), NewSimpleDuration(maxDuration), true},
{NewSimpleDuration(minDuration), NewSimpleDuration(maxDuration), false},
}
for i, test := range tests {
result := test.d1.Compare(test.d2)
if result != test.expected {
t.Errorf("TestCompare %d Failed:Expected=(%v),\nResult=(%v)", i, test.expected, result)
}
}
}
func TestDays(t *testing.T) {
tests := []struct {
d *SimpleDuration
expected float64
}{
{NewSimpleDuration(0), 0},
{NewSimpleDuration(86400 * time.Second), 1.0},
{NewSimpleDuration(365 * time.Hour * 24), 365},
{NewSimpleDuration(-365 * time.Hour * 24), -365},
{NewSimpleDuration(maxDuration), 106751.99116730066},
{NewSimpleDuration(minDuration), -106751.99116730066},
}
for i, test := range tests {
result := test.d.Days()
if result != test.expected {
t.Errorf("TestDays %d Failed:Expected=(%v),\nResult=(%v)", i, test.expected, result)
}
}
}