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

Function TestStratificationMultipleStrata

analysis/stratification_test.go:129–181  ·  view source on GitHub ↗

Separate test since multiple legitimate possible due to map iteration order.

(t *testing.T)

Source from the content-addressed store, hash-verified

127
128// Separate test since multiple legitimate possible due to map iteration order.
129func TestStratificationMultipleStrata(t *testing.T) {
130 program, err := analyze([]ast.Clause{
131 clause("node(/foo)."),
132 clause("node(/bar)."),
133 clause("edge(/foo, /bar)."),
134 clause("path(X,Y) :- edge(X,Y)."),
135 clause("path(X,Z) :- edge(X,Y), path(Y,Z)."),
136 clause("not_reachable(X, Y) :- node(X), node(Y), !path(X, Y)."),
137 clause("in_cycle_eq(X) :- node(X), path(X, Y), X = Y."),
138 clause("in_between(X, Y) :- node(X), node(Y), node(Z), path(X, Y), path(Y, Z), X != Y, Y != Z, X != Z."),
139 })
140
141 if err != nil {
142 t.Fatalf("test case unexpectedly did not pass %v", err)
143 }
144
145 strata, predToStratum, err := Stratify(Program{
146 program.EdbPredicates, program.IdbPredicates, program.Rules})
147 if err != nil {
148 t.Fatalf("expected stratification to succeed, got %v", err)
149 }
150
151 if len(strata) != 4 {
152 t.Fatalf("expected 4 strata, got %v", len(strata))
153 }
154
155 path, ok := predToStratum[ast.PredicateSym{"path", 2}]
156 if !ok {
157 t.Fatal("couldn't find 'path'")
158 }
159 inBetween, ok := predToStratum[ast.PredicateSym{"in_between", 2}]
160 if !ok {
161 t.Fatal("couldn't find 'in_between'")
162 }
163 inCycleEq, ok := predToStratum[ast.PredicateSym{"in_cycle_eq", 1}]
164 if !ok {
165 t.Fatal("couldn't find 'in_cycle_eq'")
166 }
167 notReachable, ok := predToStratum[ast.PredicateSym{"not_reachable", 2}]
168 if !ok {
169 t.Fatal("couldn't find 'not_reachable'")
170 }
171
172 if path >= inBetween {
173 t.Error("expected 'path' < 'in_between'")
174 }
175 if path >= inCycleEq {
176 t.Error("expected 'path' < 'in_cycle_eq'")
177 }
178 if path >= notReachable {
179 t.Error("expected 'path' < 'not_reachable'")
180 }
181}
182
183func TestStratificationNegative(t *testing.T) {
184 tests := []func() (*ProgramInfo, error){

Callers

nothing calls this directly

Calls 4

analyzeFunction · 0.85
StratifyFunction · 0.85
ErrorMethod · 0.80
clauseFunction · 0.70

Tested by

no test coverage detected