-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_set_test.go
101 lines (80 loc) · 2.4 KB
/
string_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
package collections
import (
"sort"
"testing"
. "github.com/smartystreets/goconvey/convey"
"go.uber.org/goleak"
)
func TestStringSet(t *testing.T) {
goleak.VerifyNone(t)
Convey("NewStringSet(...)", t, func() {
stringSet := NewStringSet()
Convey("Should not be nil", func() {
So(stringSet, ShouldNotBeNil)
})
})
Convey("NewStringSetFromArray(...)", t, func() {
stringSet := NewStringSetFromArray([]string{
"oneThing",
"twoThing",
"redThing",
"blueThing",
})
Convey("Should not be nil", func() {
So(stringSet, ShouldNotBeNil)
})
Convey("Should have 4 members", func() {
So(stringSet.Size(), ShouldEqual, 4)
})
Convey("Should have the expected members", func() {
So(stringSet.Contains("oneThing"), ShouldBeTrue)
So(stringSet.Contains("twoThing"), ShouldBeTrue)
So(stringSet.Contains("redThing"), ShouldBeTrue)
So(stringSet.Contains("blueThing"), ShouldBeTrue)
})
})
Convey("StringSet.Size()", t, func() {
stringSet := NewStringSetFromArray([]string{"1", "2"})
Convey("Should return 2", func() {
So(stringSet.Size(), ShouldEqual, 2)
})
})
Convey("StringSet.Contains(...)", t, func() {
stringSet := NewStringSetFromArray([]string{"1", "2"})
Convey("Should return true when given an element in the set", func() {
So(stringSet.Contains("1"), ShouldBeTrue)
So(stringSet.Contains("2"), ShouldBeTrue)
})
Convey("Should return false when given an element not in the set", func() {
So(stringSet.Contains("3"), ShouldBeFalse)
})
})
Convey("StringSet.Add(...)", t, func() {
stringSet := NewStringSet()
stringSet.Add("x")
stringSet.Add("y")
Convey("Should have added the specified elements", func() {
So(stringSet.Size(), ShouldEqual, 2)
})
})
Convey("StringSet.Remove(...)", t, func() {
stringSet := NewStringSetFromArray([]string{"1", "2"})
stringSet.Remove("1")
Convey("Should have removed the specified element", func() {
So(stringSet.Contains("1"), ShouldBeFalse)
})
Convey("Should not have removed other elements", func() {
So(stringSet.Contains("2"), ShouldBeTrue)
})
})
Convey("StringSet.Members()", t, func() {
stringSet := NewStringSetFromArray([]string{"1", "2"})
members := stringSet.Members()
sort.Strings(members)
Convey("Should return an array of the members of the set", func() {
So(len(members), ShouldEqual, 2)
So(members[0], ShouldEqual, "1")
So(members[1], ShouldEqual, "2")
})
})
}