-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathset_test.go
80 lines (69 loc) · 1.46 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
package maps
import (
"encoding/gob"
"fmt"
"github.com/stretchr/testify/assert"
"slices"
"testing"
)
type setT = Set[string]
type setTI = SetI[string]
func TestSet_SetI(t *testing.T) {
runSetITests[Set[string]](t, makeSetI[Set[string]])
}
func init() {
gob.Register(new(Set[string]))
}
func ExampleSet_String() {
m := new(Set[string])
m.Add("a")
fmt.Print(m.String())
// Output: {"a"}
}
func TestCollectSet(t *testing.T) {
m1 := NewSet("a", "b", "c")
m2 := CollectSet(m1.All())
fmt.Println(m2.String())
assert.True(t, m1.Equal(m2))
}
func TestSet_Clone(t *testing.T) {
m1 := NewSet("a", "b", "c")
m2 := CollectSet(m1.All())
m3 := m2.Clone()
assert.True(t, m1.Equal(m3))
}
func TestSet_Nil(t *testing.T) {
t.Run("Nil", func(t *testing.T) {
var m1, m2 *Set[string]
assert.Equal(t, 0, m1.Len())
m1.Clear()
assert.True(t, m1.Equal(m2))
m3 := m2.Clone()
assert.True(t, m1.Equal(m3))
m3.Add("a")
assert.False(t, m1.Equal(m3))
m1.Range(func(k string) bool {
assert.Fail(t, "no range should happen")
return false
})
assert.False(t, m1.Has("b"))
m1.Delete("a")
assert.Empty(t, m1.Values())
assert.Equal(t, "{}", m1.String())
m1.DeleteFunc(func(k string) bool {
return false
})
for _ = range m1.All() {
assert.Fail(t, "no range should happen")
}
assert.Panics(t, func() {
m1.Insert(slices.Values([]string{"a"}))
})
assert.Panics(t, func() {
m1.Add("a")
})
assert.Panics(t, func() {
m1.Copy(m2)
})
})
}