MCPcopy
hub / github.com/google/mangle / TestStore

Function TestStore

factstore/simplecolumn_test.go:119–172  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func TestStore(t *testing.T) {
120 m := testStore(t)
121 sc := SimpleColumn{true /* deterministic */}
122 var buf bytes.Buffer
123 if err := sc.WriteTo(m, &buf); err != nil {
124 t.Fatal(err)
125 }
126
127 s, err := NewSimpleColumnStore(func() (io.ReadCloser, error) {
128 return io.NopCloser(bytes.NewReader(buf.Bytes())), nil
129 })
130
131 if err != nil {
132 t.Fatal(err)
133 }
134
135 if len(s.predicateFactCount) != len(m.ListPredicates()) {
136 t.Errorf("NewSimpleColumnStore: got %d predicates want %d", len(s.predicateFactCount), len(m.ListPredicates()))
137 }
138
139 var foundBaz bool
140 s.GetFacts(atom("baz()"), func(a ast.Atom) error {
141 if !a.Equals(atom("baz()")) {
142 t.Errorf("GetFacts(baz()): got %v want baz()", a)
143 }
144 foundBaz = true
145 return nil
146 })
147 if !foundBaz {
148 t.Errorf("GetFacts(baz()): got nothing want baz()")
149 }
150
151 tests := []struct {
152 query string
153 want int
154 }{
155 {"foo(X)", wantNumFooFacts},
156 {"bar(X, Y, Z)", wantNumBarFacts},
157 {"qaz(X, Y, Z)", wantNumQazFacts},
158 }
159 for _, test := range tests {
160 var count int
161 s.GetFacts(atom(test.query), func(a ast.Atom) error {
162 if !m.Contains(a) {
163 t.Errorf("GetFacts(%s): unexpected fact: %v", test.query, a)
164 }
165 count++
166 return nil
167 })
168 if count != test.want {
169 t.Errorf("GetFacts(%s): got %d want %d facts", test.query, count, test.want)
170 }
171 }
172}
173
174func TestFiltered(t *testing.T) {
175 m := testStore(t)

Callers

nothing calls this directly

Calls 8

WriteToMethod · 0.95
GetFactsMethod · 0.95
testStoreFunction · 0.85
NewSimpleColumnStoreFunction · 0.85
atomFunction · 0.70
ListPredicatesMethod · 0.65
EqualsMethod · 0.65
ContainsMethod · 0.65

Tested by

no test coverage detected