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

Function TestReduce

engine/transformer_test.go:73–106  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

71}
72
73func TestReduce(t *testing.T) {
74 tests := []testCase{
75 {
76 initialFacts: []ast.Atom{atom("bar(0)"), atom("bar(1)")},
77 clause: clause("foo(X) :- bar(Y) |> do fn:group_by(), let X = fn:sum(Y)."),
78 expectedFacts: []ast.Atom{atom("foo(1)")},
79 },
80 {
81 initialFacts: []ast.Atom{atom("bar(0)"), atom("bar(1)")},
82 clause: clause("foo(X) :- bar(Y) |> do fn:group_by(), let X = fn:count()."),
83 expectedFacts: []ast.Atom{atom("foo(2)")},
84 },
85 {
86 initialFacts: []ast.Atom{atom("bar(0)"), atom("bar(1)")},
87 clause: clause("foo(X) :- bar(Y) |> do fn:group_by(), let X = fn:min(Y)."),
88 expectedFacts: []ast.Atom{atom("foo(0)")},
89 },
90 {
91 initialFacts: []ast.Atom{atom("bar(0)"), atom("bar(1)")},
92 clause: clause("foo(Min, Max) :- bar(Y) |> do fn:group_by(), let Min = fn:min(Y), let Max = fn:max(Y)."),
93 expectedFacts: []ast.Atom{atom("foo(0, 1)")},
94 },
95 // An alternative way to fn:count()
96 {
97 initialFacts: []ast.Atom{atom("bar(0)"), atom("bar(1)")},
98 clause: clause("foo(Num) :- bar(Y) |> do fn:group_by(), let L = fn:collect(Y), let Num = fn:list:len(L)."),
99 expectedFacts: []ast.Atom{atom("foo(2)")},
100 },
101 }
102
103 for _, test := range tests {
104 runEval(test, t)
105 }
106}
107
108func TestGroupBy(t *testing.T) {
109 tests := []testCase{

Callers

nothing calls this directly

Calls 3

runEvalFunction · 0.85
atomFunction · 0.70
clauseFunction · 0.70

Tested by

no test coverage detected