-
Notifications
You must be signed in to change notification settings - Fork 2
/
intersection_test.go
67 lines (58 loc) · 1.5 KB
/
intersection_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
package set
import (
"testing"
)
func TestDefFiniteIntersectionBroken(t *testing.T) {
if _, err := defFiniteIntersection(infinitegt3, infinitegt3); err == nil {
t.Error("First set not definitely finite but no error")
}
}
func TestDefFiniteIntersection(t *testing.T) {
set, err := defFiniteIntersection(finite123, infinitegt3)
if err != nil {
t.Fatal(err)
}
if !set.DefinitelyFinite() {
t.Fatal("Set should be definitely finite")
}
if list, err := set.List(); err != nil {
t.Fatal(err)
} else if !(len(list) == 1 && list[0] == 3) {
t.Error("Wrong set")
}
}
func TestNotDefFiniteIntersection(t *testing.T) {
set, err := notDefFiniteIntersection(infinitegt3, infinitelt3)
if err != nil {
t.Fatal(err)
}
if yes, err := set.Contains(3); err != nil {
t.Fatal(err)
} else if !yes {
t.Error("3 not in set")
}
for _, element := range []int{1, 2, 4, 5, 6} {
if yes, err := set.Contains(element); err != nil {
t.Fatal(err)
} else if yes {
t.Errorf("%v in set", element)
}
}
}
func TestIntersection(t *testing.T) {
if set, err := Intersection(finite123, infinitegt3); err != nil {
t.Error(err)
} else if !set.DefinitelyFinite() {
t.Error("Set not definitely finite")
}
if set, err := Intersection(infinitegt3, finite123); err != nil {
t.Error(err)
} else if !set.DefinitelyFinite() {
t.Error("Set not definitely finite")
}
if set, err := Intersection(infinitegt3, infinitegt3); err != nil {
t.Error(err)
} else if set.DefinitelyFinite() {
t.Error("Set definitely finite")
}
}