-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunion_test.go
66 lines (57 loc) · 1.23 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
package intervals_test
import (
"testing"
. "github.com/b97tsk/intervals"
"github.com/b97tsk/intervals/elems"
)
func TestUnion(t *testing.T) {
type E = elems.Int
testCases := []struct {
Actual, Expected Set[E]
}{
{
Set[E]{{1, 3}, {5, 7}}.Union(Set[E]{}),
Set[E]{{1, 3}, {5, 7}},
},
{
Set[E]{}.Union(Set[E]{{1, 3}, {5, 7}}),
Set[E]{{1, 3}, {5, 7}},
},
{
Set[E]{{5, 7}}.Union(Set[E]{{1, 3}}),
Set[E]{{1, 3}, {5, 7}},
},
{
Set[E]{{3, 7}}.Union(Set[E]{{1, 5}}),
Set[E]{{1, 7}},
},
{
Set[E]{{3, 11}, {13, 21}}.Union(Set[E]{{1, 5}, {9, 15}, {19, 23}}),
Set[E]{{1, 23}},
},
{Reduce(Union[E]), Set[E]{}},
{Reduce(Union, Set[E]{}), Set[E]{}},
{
func() Set[E] {
var x2, x3, x5 Set[E]
for i := 2; i < 32; i += 2 {
x2 = Add(x2, Unit(E(i)))
}
for i := 3; i < 32; i += 3 {
x3 = Add(x3, Unit(E(i)))
}
for i := 5; i < 32; i += 5 {
x5 = Add(x5, Unit(E(i)))
}
return Reduce(Union, x2, x3, x5)
}(),
Set[E]{{2, 7}, {8, 11}, {12, 13}, {14, 17}, {18, 19}, {20, 23}, {24, 29}, {30, 31}},
},
}
for i, c := range testCases {
if !c.Actual.Equal(c.Expected) {
t.Fail()
t.Logf("Case %v: want %v, but got %v", i, c.Expected, c.Actual)
}
}
}