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

Function runEvaluate

examples/examples_test.go:88–131  ·  view source on GitHub ↗

Helpers

(t *testing.T, program string)

Source from the content-addressed store, hash-verified

86// Helpers
87
88func runEvaluate(t *testing.T, program string) []factstore.TemporalFact {
89 unit, err := parse.Unit(strings.NewReader(program))
90 if err != nil {
91 t.Fatalf("Parse failed: %v", err)
92 }
93
94 programInfo, err := analysis.AnalyzeOneUnit(unit, nil)
95 if err != nil {
96 t.Fatalf("Analyze failed: %v", err)
97 }
98
99 store := factstore.NewTemporalStore()
100 err = engine.EvalProgram(programInfo, factstore.NewTemporalFactStoreAdapter(store),
101 engine.WithTemporalStore(store))
102 if err != nil {
103 t.Fatalf("Eval failed: %v", err)
104 }
105
106 var facts []factstore.TemporalFact
107 // Collect all facts
108 // We iterate over all predicates
109 for pred := range programInfo.Decls {
110 query := ast.Atom{Predicate: pred}
111 // Creating a dummy query atom with variables is hard without knowing arity/types easily
112 // But store.GetAllFacts takes a query atom.
113 // Let's just assume we can query everything.
114 // Actually, GetAllFacts isn't exposed on the interface easily like that?
115 // store.GetAllFacts takes a callback.
116 // We'll construct a query with variables.
117 args := make([]ast.BaseTerm, pred.Arity)
118 for i := 0; i < pred.Arity; i++ {
119 args[i] = ast.Variable{Symbol: "X"} // Same var ok? No, better unique.
120 }
121 query.Args = args
122
123 store.GetAllFacts(query, func(tf factstore.TemporalFact) error {
124 facts = append(facts, tf)
125 return nil
126 })
127 }
128 // Also for match(Name), which is not temporal in sequence test
129 // Ideally we check EDB/IDB predicates.
130 return facts
131}
132
133func containsFact(facts []factstore.TemporalFact, prefix string) bool {
134 for _, f := range facts {

Callers 3

TestTemporalGraphPointsFunction · 0.85
TestTemporalSequenceFunction · 0.85

Calls 7

GetAllFactsMethod · 0.95
UnitFunction · 0.92
AnalyzeOneUnitFunction · 0.92
NewTemporalStoreFunction · 0.92
EvalProgramFunction · 0.92
WithTemporalStoreFunction · 0.92

Tested by

no test coverage detected