-
Notifications
You must be signed in to change notification settings - Fork 0
/
period_time_test.go
53 lines (50 loc) · 1.13 KB
/
period_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
package gf
import (
"testing"
"time"
)
func TestPTSliceUnion(t *testing.T) {
tests := []struct {
name string
wantSum int64
}{
{
name: "success_union",
wantSum: 46800,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := NewPeriodTime()
p.Append(time.Now(), time.Now().Add(2*time.Hour))
p.Append(time.Now().Add(-1*time.Hour), time.Now().Add(1*time.Hour))
p.Append(time.Now().Add(10*time.Hour), time.Now().Add(20*time.Hour))
duration := p.Union().Duration()
if duration != tt.wantSum {
t.Errorf("Duration() = %v, want %v", duration, tt.wantSum)
}
})
}
}
func TestPTSliceIntersect(t *testing.T) {
tests := []struct {
name string
wantSum int64
}{
{
name: "success_union",
wantSum: 3600,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := NewPeriodTime()
p.Append(time.Now(), time.Now().Add(2*time.Hour))
p.Append(time.Now().Add(-1*time.Hour), time.Now().Add(1*time.Hour))
duration := p.Intersect().Duration()
if duration != tt.wantSum {
t.Errorf("Duration() = %v, want %v", duration, tt.wantSum)
}
})
}
}