-
Notifications
You must be signed in to change notification settings - Fork 2
/
interval_test.go
108 lines (105 loc) · 1.42 KB
/
interval_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package easy
import (
"reflect"
"testing"
)
var mergeIntervalTests = []struct {
intervals []Interval[int, int]
want []Interval[int, int]
}{
{
intervals: []Interval[int, int]{
{
Left: 900,
Right: 960,
Power: 100,
},
{
Left: 930,
Right: 990,
Power: 50,
},
},
want: []Interval[int, int]{
{
Left: 900,
Right: 930,
Power: 100,
},
{
Left: 930,
Right: 960,
Power: 150,
},
{
Left: 960,
Right: 990,
Power: 50,
},
},
},
{
intervals: []Interval[int, int]{
{
Left: 100,
Right: 200,
Power: 100,
},
{
Left: 300,
Right: 500,
Power: 50,
},
{
Left: 400,
Right: 450,
Power: 120,
},
{
Left: 400,
Right: 500,
Power: 20,
},
{
Left: 1000,
Right: 1500,
Power: 200,
},
},
want: []Interval[int, int]{
{
Left: 100,
Right: 200,
Power: 100,
},
{
Left: 300,
Right: 400,
Power: 50,
},
{
Left: 400,
Right: 450,
Power: 190,
},
{
Left: 450,
Right: 500,
Power: 70,
},
{
Left: 1000,
Right: 1500,
Power: 200,
},
},
},
}
func TestMergeIntervals(t *testing.T) {
for _, test := range mergeIntervalTests {
got := MergeIntervals(test.intervals...)
if !reflect.DeepEqual(got, test.want) {
t.Errorf("MergeIntervals(%v) = %v, want %v", test.intervals, got, test.want)
}
}
}