-
Notifications
You must be signed in to change notification settings - Fork 97
/
union_test.go
74 lines (70 loc) · 2.05 KB
/
union_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
// Copyright (c) 2016, Peter Mrekaj. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE.txt file.
package sorting
import (
"reflect"
"testing"
)
func TestUnionOfIntervals(t *testing.T) {
for _, test := range []struct {
in []Interval
want []Interval
}{
{nil, nil},
{
[]Interval{
{EndPoint{true, 0}, EndPoint{true, 4}},
{EndPoint{true, 0}, EndPoint{true, 5}}},
[]Interval{{EndPoint{true, 0}, EndPoint{true, 5}}},
},
{
[]Interval{
{EndPoint{true, 1}, EndPoint{true, 5}},
{EndPoint{true, 0}, EndPoint{true, 4}}},
[]Interval{{EndPoint{true, 0}, EndPoint{true, 5}}},
},
{
[]Interval{
{EndPoint{true, 0}, EndPoint{true, 5}},
{EndPoint{true, 0}, EndPoint{true, 4}}},
[]Interval{{EndPoint{true, 0}, EndPoint{true, 5}}},
},
{
[]Interval{
{EndPoint{true, 1}, EndPoint{true, 3}},
{EndPoint{true, 0}, EndPoint{true, 4}}},
[]Interval{{EndPoint{true, 0}, EndPoint{true, 4}}},
},
{
[]Interval{
{EndPoint{true, 1}, EndPoint{true, 5}},
{EndPoint{true, 0}, EndPoint{true, 4}}},
[]Interval{{EndPoint{true, 0}, EndPoint{true, 5}}},
},
{
[]Interval{
{EndPoint{true, 2}, EndPoint{true, 4}},
{EndPoint{true, 8}, EndPoint{false, 11}},
{EndPoint{false, 13}, EndPoint{false, 15}},
{EndPoint{false, 16}, EndPoint{false, 17}},
{EndPoint{true, 1}, EndPoint{true, 1}},
{EndPoint{true, 3}, EndPoint{false, 4}},
{EndPoint{true, 7}, EndPoint{false, 8}},
{EndPoint{false, 12}, EndPoint{true, 16}},
{EndPoint{false, 0}, EndPoint{false, 3}},
{EndPoint{true, 5}, EndPoint{false, 7}},
{EndPoint{false, 9}, EndPoint{true, 11}},
{EndPoint{true, 12}, EndPoint{true, 14}}},
[]Interval{
{EndPoint{false, 0}, EndPoint{true, 4}},
{EndPoint{true, 5}, EndPoint{true, 11}},
{EndPoint{true, 12}, EndPoint{false, 17}}},
},
} {
if got := UnionOfIntervals(test.in); !reflect.DeepEqual(got, test.want) {
t.Errorf("UnionOfIntervals(%v) = %v; want %v", test.in, got, test.want)
}
}
}
// TODO: benchmark!