-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
store_test.go
62 lines (58 loc) · 1.18 KB
/
store_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 graph
import (
"errors"
"testing"
)
func TestRemoveEdge(t *testing.T) {
noerr := func(err error) {
if err != nil {
panic(err)
}
}
build := func(nodes []string, edges [][]string) Store[string, string] {
store := newMemoryStore[string, string]()
for _, n := range nodes {
noerr(store.AddVertex(n, n, VertexProperties{}))
}
for _, e := range edges {
noerr(store.AddEdge(e[0], e[1], Edge[string]{
Source: e[0],
Target: e[1],
}))
}
return store
}
t.Run("normal remove", func(t *testing.T) {
g := build([]string{
"a", "b", "c",
}, [][]string{
{"a", "b"},
{"a", "c"},
})
noerr(g.RemoveEdge("a", "b"))
noerr(g.RemoveEdge("a", "c"))
noerr(g.RemoveVertex("a"))
})
t.Run("remove edge has in-edges", func(t *testing.T) {
g := build([]string{
"a", "b", "c",
}, [][]string{
{"a", "b"},
{"a", "c"},
})
if err := g.RemoveVertex("b"); !errors.Is(err, ErrVertexHasEdges) {
t.Fail()
}
})
t.Run("remove edge has out-edges", func(t *testing.T) {
g := build([]string{
"a", "b", "c",
}, [][]string{
{"a", "b"},
{"a", "c"},
})
if err := g.RemoveVertex("a"); !errors.Is(err, ErrVertexHasEdges) {
t.Fail()
}
})
}