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

Function TestTransform

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

Source from the content-addressed store, hash-verified

502}
503
504func TestTransform(t *testing.T) {
505 store := factstore.NewSimpleInMemoryStore()
506 facts := []ast.Atom{
507 atom("node(/a)"),
508 atom("node(/b)"),
509 atom("node(/c)"),
510 atom("node(/d)"),
511 atom("edge(/a,/b)"),
512 atom("edge(/b,/c)"),
513 atom("edge(/c,/d)"),
514 atom("label(/a, 100)"),
515 atom("label(/b, 20)"),
516 atom("label(/c, 50)"),
517 atom("label(/d, 500)"),
518 atom("decompose_pair(1, 2)"),
519 ast.NewAtom("decompose_cons", ast.Number(1), ast.ListNil),
520 atom("decompose_nil()"),
521 }
522 for _, fact := range facts {
523 store.Add(fact)
524 }
525 program := []ast.Clause{
526 clause(`max_inner(Max, fn:pair(1,2)) :-
527 node(Y), edge(X, Y), edge(Y, _), label(Y, N)
528 |> do fn:group_by(), let Max = fn:max(N).`),
529 }
530 if err := analyzeAndEvalProgram(t, program, store); err != nil {
531 t.Errorf("Program evaluation failed %v program %v", err, program)
532 return
533 }
534
535 wantAtom, err := functional.EvalAtom(atom("max_inner(50, fn:pair(1,2))"), ast.ConstSubstList{})
536 if err != nil {
537 t.Fatal(err)
538 }
539 expected := []ast.Atom{
540 wantAtom,
541 }
542
543 for _, fact := range expected {
544 if !store.Contains(fact) {
545 t.Errorf("expected fact %v in store %v", fact, store)
546 }
547 }
548 for _, p := range store.ListPredicates() {
549 store.GetFacts(ast.NewQuery(p), func(a ast.Atom) error {
550 for _, arg := range a.Args {
551 _, ok := arg.(ast.Constant)
552 if !ok {
553 t.Fatalf("found non constant %v %T in atom %v", arg, arg, a)
554 }
555 }
556 return nil
557 })
558 }
559}
560
561func TestCreatedFactLimit(t *testing.T) {

Callers

nothing calls this directly

Calls 12

AddMethod · 0.95
ContainsMethod · 0.95
ListPredicatesMethod · 0.95
GetFactsMethod · 0.95
NewSimpleInMemoryStoreFunction · 0.92
NewAtomFunction · 0.92
NumberFunction · 0.92
EvalAtomFunction · 0.92
NewQueryFunction · 0.92
analyzeAndEvalProgramFunction · 0.85
atomFunction · 0.70
clauseFunction · 0.70

Tested by

no test coverage detected