-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathphantom_object_map_test.go
43 lines (39 loc) · 1.46 KB
/
phantom_object_map_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
package main
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestPhantomObjectMapAdd(t *testing.T) {
pom := NewPhantomObjectMap()
assert.Equal(t, true, pom.Add(&PhantomObjectInfo{Key: Path{"", "a", "b"}}))
assert.Equal(t, 1, pom.Size())
assert.Equal(t, false, pom.Add(&PhantomObjectInfo{Key: Path{"", "a", "b"}}))
assert.Equal(t, 1, pom.Size())
assert.Equal(t, true, pom.Add(&PhantomObjectInfo{Key: Path{"", "a", "c"}}))
assert.Equal(t, 2, pom.Size())
assert.Equal(t, true, pom.Add(&PhantomObjectInfo{Key: Path{"", "a", "b", "c"}}))
assert.Equal(t, 3, pom.Size())
}
func TestPhantomObjectMapRemove(t *testing.T) {
pom := NewPhantomObjectMap()
o1 := &PhantomObjectInfo{Key: Path{"", "a", "b"}}
o2 := &PhantomObjectInfo{Key: Path{"", "a", "b"}}
o3 := &PhantomObjectInfo{Key: Path{"", "a", "c"}}
o4 := &PhantomObjectInfo{Key: Path{"", "a", "b", "c"}}
assert.Equal(t, true, pom.Add(o1))
assert.Equal(t, 1, pom.Size())
assert.Equal(t, false, pom.Add(o2))
assert.Equal(t, 1, pom.Size())
assert.Equal(t, true, pom.Add(o3))
assert.Equal(t, 2, pom.Size())
assert.Equal(t, true, pom.Add(o4))
assert.Equal(t, 3, pom.Size())
assert.Equal(t, o3, pom.Remove(Path{"", "a", "c"}))
assert.Nil(t, pom.Get(Path{"", "a", "c"}))
assert.Equal(t, 2, pom.Size())
assert.Nil(t, pom.Remove(Path{"", "a", "c"}))
assert.Equal(t, 2, pom.Size())
assert.Equal(t, o2, pom.Remove(Path{"", "a", "b"}))
assert.Equal(t, 1, pom.Size())
assert.Nil(t, pom.Get(Path{"", "a", "b"}))
}