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

Function TestSimpleEvalDefer

engine/seminaivebottomup_test.go:329–369  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

327}
328
329func TestSimpleEvalDefer(t *testing.T) {
330 store := factstore.NewSimpleInMemoryStore()
331 store.Add(atom("node(/a)"))
332 store.Add(atom("node(/b)"))
333 store.Add(atom("node(/c)"))
334 store.Add(atom("edge(/a,/b)"))
335 store.Add(atom("edge(/b,/c)"))
336 store.Add(atom("label(/a, 100)"))
337
338 if err := analyzeAndEvalProgram(t, program, store, func(opt *EvalOptions) {
339 // Evaluate only this particular predicate and nothing else.
340 predicateAllowList := func(sym ast.PredicateSym) bool {
341 return sym == ast.PredicateSym{"path", 2}
342 }
343 opt.predicateAllowList = &predicateAllowList
344 }); err != nil {
345 t.Errorf("Program evaluation failed %v program %v", err, program)
346 return
347 }
348
349 expected := []ast.Atom{
350 atom("node(/a)"),
351 atom("node(/b)"),
352 atom("node(/c)"),
353 atom("edge(/a,/b)"),
354 atom("edge(/b,/c)"),
355 atom("label(/a, 100)"),
356 atom("path(/a,/b)"),
357 atom("path(/a,/c)"),
358 atom("path(/b,/c)"),
359 }
360
361 for _, fact := range expected {
362 if !store.Contains(fact) {
363 t.Errorf("expected fact %v in store %v", fact, store)
364 }
365 }
366 if store.EstimateFactCount() > len(expected) {
367 t.Errorf("extra facts: %v", store)
368 }
369}
370
371func TestManyPaths(t *testing.T) {
372 store := factstore.NewSimpleInMemoryStore()

Callers

nothing calls this directly

Calls 6

AddMethod · 0.95
ContainsMethod · 0.95
EstimateFactCountMethod · 0.95
NewSimpleInMemoryStoreFunction · 0.92
analyzeAndEvalProgramFunction · 0.85
atomFunction · 0.70

Tested by

no test coverage detected