-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_suite_test.go
66 lines (51 loc) · 1.09 KB
/
set_suite_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 set
import (
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "go-algorithms/data_structures/types"
)
var _ = Describe("set", func() {
var set Set
AssertSetBehavior := func() {
It("should be empty", func() {
Expect(set.IsEmpty()).To(BeTrue())
Expect(set.Size()).To(BeZero())
})
Specify("add elements", func() {
for i := 0; i < 100; i++ {
set.Add(T(i))
}
for i := 0; i < 60; i++ {
set.Add(T(i))
}
Expect(set.Size()).To(Equal(100))
})
Specify("remove elements", func() {
for i := 0; i < 60; i++ {
set.Remove(T(i))
}
})
It("can know whether key contains", func() {
Expect(set.Contains(1)).To(Equal(false))
Expect(set.Contains(100)).To(Equal(false))
Expect(set.Contains(88)).To(Equal(true))
})
}
Describe("BSTSet", Ordered, func() {
BeforeAll(func() {
set = NewBSTSet()
})
AssertSetBehavior()
})
Describe("HashSet", Ordered, func() {
BeforeAll(func() {
set = NewHashSet()
})
AssertSetBehavior()
})
})
func TestSet(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Set Suite")
}