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

Function TestStratificationPositive

analysis/stratification_test.go:51–126  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

49}
50
51func TestStratificationPositive(t *testing.T) {
52 tests := []struct {
53 name string
54 program func() (*ProgramInfo, error)
55 wantStrataOrder map[int][]ast.PredicateSym
56 }{
57 {
58 name: "Ignore built-in predicates",
59 program: func() (*ProgramInfo, error) {
60 return analyze([]ast.Clause{
61 clause("foo(X) :- :list:member(X, [/a])."),
62 })
63 },
64 wantStrataOrder: map[int][]ast.PredicateSym{
65 0: {{"foo", 1}},
66 },
67 },
68 {
69 name: "Cycles are ok as long as they are positive",
70 program: func() (*ProgramInfo, error) {
71 return analyze([]ast.Clause{
72 clause("num(/one)."),
73 clause("num(/two)."),
74 clause("num(/three)."),
75 clause("succ(/one, /two)."),
76 clause("succ(/two, /three)."),
77 clause("odd(/one)."),
78 clause("odd(X) :- num(X), succ(Y,X), even(Y)."),
79 clause("even(X) :- num(X), succ(X,Y), odd(X)."),
80 clause("count(Z) :- odd(X) |> do fn:group_by(), let Z = fn:count()."),
81 })
82 },
83 wantStrataOrder: map[int][]ast.PredicateSym{
84 0: {{"even", 1}, {"odd", 1}},
85 1: {{"count", 1}},
86 },
87 },
88 {
89 name: "The result is ordered by dependencies",
90 program: func() (*ProgramInfo, error) {
91 return analyze([]ast.Clause{
92 clause("num(/one)."),
93 clause("a(X) :- num(X), b(X)."),
94 clause("b(X) :- num(X), c(X)."),
95 clause("c(X) :- num(X), d(X), b(X)."),
96 clause("d(X) :- num(X)."),
97 })
98 },
99 wantStrataOrder: map[int][]ast.PredicateSym{
100 0: {{"d", 1}},
101 1: {{"b", 1}, {"c", 1}},
102 2: {{"a", 1}},
103 },
104 },
105 }
106 for _, test := range tests {
107 t.Run(test.name, func(t *testing.T) {
108 program, err := test.program()

Callers

nothing calls this directly

Calls 4

analyzeFunction · 0.85
StratifyFunction · 0.85
toOrderMapFunction · 0.85
clauseFunction · 0.70

Tested by

no test coverage detected