-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_test.go
62 lines (58 loc) · 1.17 KB
/
string_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
package container
import (
"reflect"
"testing"
)
func TestStringMap(t *testing.T) {
var (
m = make(MapDefault)
a = "a"
b = "b"
)
m["a"] = a
if v := m.Lookup("a", b); v != a {
t.Errorf("got %v, want %v", v, a)
}
if v := m.Lookup("b", b); v != b {
t.Errorf("got %v, want %s", v, b)
}
}
func TestStringSliceMap(t *testing.T) {
var (
m = make(MapSliceDefault)
a = []string{"a"}
b = []string{"b"}
)
m["a"] = a
if v := m.Lookup("a", b); !reflect.DeepEqual(v, a) {
t.Errorf("got %v, want %v", v, a)
}
if v := m.Lookup("b", b); !reflect.DeepEqual(v, b) {
t.Errorf("got %v, want %v", v, b)
}
}
func TestStringSet(t *testing.T) {
ss := NewStringSet()
if ss.Size() != 0 {
t.Errorf("empty set should be 0")
}
ss.Add("a")
if ss.Size() != 1 {
t.Errorf("expected size 1")
}
if !ss.Contains("a") {
t.Errorf("expected a in set")
}
ss.Add("a")
ss.Add("c", "b")
if exp := []string{"a", "b", "c"}; !reflect.DeepEqual(ss.SortedValues(), exp) {
t.Errorf("expected: %s", exp)
}
st := NewStringSet("a", "x")
if st.Intersection(ss).Size() != 1 {
t.Errorf("expected overlap of 1")
}
if st.Difference(ss).Size() != 1 {
t.Errorf("expected difference of 1")
}
}