forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_test.go
113 lines (90 loc) · 1.84 KB
/
set_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
109
110
111
112
113
package schema
import (
"reflect"
"testing"
)
func TestSetAdd(t *testing.T) {
s := &Set{F: testSetInt}
s.Add(1)
s.Add(5)
s.Add(25)
expected := []interface{}{1, 25, 5}
actual := s.List()
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}
}
func TestSetAdd_negative(t *testing.T) {
// Since we don't allow negative hashes, this should just hash to the
// same thing...
s := &Set{F: testSetInt}
s.Add(-1)
s.Add(1)
expected := []interface{}{-1}
actual := s.List()
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}
}
func TestSetContains(t *testing.T) {
s := &Set{F: testSetInt}
s.Add(5)
s.Add(-5)
if s.Contains(2) {
t.Fatal("should not contain")
}
if !s.Contains(5) {
t.Fatal("should contain")
}
if !s.Contains(-5) {
t.Fatal("should contain")
}
}
func TestSetDifference(t *testing.T) {
s1 := &Set{F: testSetInt}
s2 := &Set{F: testSetInt}
s1.Add(1)
s1.Add(5)
s2.Add(5)
s2.Add(25)
difference := s1.Difference(s2)
difference.Add(2)
expected := []interface{}{1, 2}
actual := difference.List()
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}
}
func TestSetIntersection(t *testing.T) {
s1 := &Set{F: testSetInt}
s2 := &Set{F: testSetInt}
s1.Add(1)
s1.Add(5)
s2.Add(5)
s2.Add(25)
intersection := s1.Intersection(s2)
intersection.Add(2)
expected := []interface{}{2, 5}
actual := intersection.List()
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}
}
func TestSetUnion(t *testing.T) {
s1 := &Set{F: testSetInt}
s2 := &Set{F: testSetInt}
s1.Add(1)
s1.Add(5)
s2.Add(5)
s2.Add(25)
union := s1.Union(s2)
union.Add(2)
expected := []interface{}{1, 2, 25, 5}
actual := union.List()
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}
}
func testSetInt(v interface{}) int {
return v.(int)
}