-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraphview_test.go
81 lines (66 loc) · 1.73 KB
/
graphview_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
81
package store4_test
import (
. "github.com/jimsmart/store4"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
type Triple struct {
S string
P string
O interface{}
}
func (t Triple) Subject() string { return t.S }
func (t Triple) Predicate() string { return t.P }
func (t Triple) Object() interface{} { return t.O }
var _ = Describe("GraphView", func() {
Describe("Creating a new GraphView", func() {
Context("from [][3]string", func() {
graph := NewGraph([][3]string{
{"s1", "p1", "o1"},
{"s1", "p1", "o2"},
{"s1", "p2", "o2"},
{"s2", "p1", "o1"},
{"s1", "p2", "o3"},
})
It("should have size 5", func() {
Expect(graph.Size()).To(Equal(uint64(5)))
})
It("should contain the correct triples", func() {
var resultsList []*Triple
graph.ForEach(func(s, p string, o interface{}) {
resultsList = append(resultsList, &Triple{s, p, o})
})
Expect(resultsList).To(ConsistOf([]*Triple{
{"s1", "p1", "o1"},
{"s1", "p1", "o2"},
{"s1", "p2", "o2"},
{"s2", "p1", "o1"},
{"s1", "p2", "o3"},
}))
})
})
Context("from a single [3]string", func() {
graph := NewGraph([3]string{"s1", "p1", "o1"})
It("should have size 1", func() {
Expect(graph.Size()).To(Equal(uint64(1)))
})
It("should contain the correct triple", func() {
var resultsList []*Triple
graph.ForEach(func(s, p string, o interface{}) {
resultsList = append(resultsList, &Triple{s, p, o})
})
Expect(resultsList).To(ConsistOf([]*Triple{
{"s1", "p1", "o1"},
}))
})
})
Context("from an unknown type", func() {
shouldPanic := func() {
NewGraph(true)
}
It("should panic", func() {
Expect(shouldPanic).To(Panic())
})
})
})
})