| 106 | } |
| 107 | |
| 108 | func TestGroupBy(t *testing.T) { |
| 109 | tests := []testCase{ |
| 110 | { |
| 111 | initialFacts: []ast.Atom{atom("bar(0, 11)"), atom("bar(0, 12)")}, |
| 112 | clause: clause("foo(Y, X) :- bar(Y, Z) |> do fn:group_by(Y), let X = fn:sum(Z)."), |
| 113 | expectedFacts: []ast.Atom{atom("foo(0, 23)")}, |
| 114 | }, |
| 115 | { |
| 116 | initialFacts: []ast.Atom{ |
| 117 | atom(`bar("a", 11, 100)`), |
| 118 | atom(`bar("a", 11, 150)`), |
| 119 | atom(`bar("b", 3, 200))`), |
| 120 | }, |
| 121 | clause: clause(`foo(Y, Count, Sum, Max) :- bar(Y, Z, A) |
| 122 | |> do fn:group_by(Y), let Count = fn:count(), let Sum = fn:sum(Z), let Max = fn:max(A).`), |
| 123 | expectedFacts: []ast.Atom{ |
| 124 | atom(`foo("a", 2, 22, 150)`), |
| 125 | atom(`foo("b", 1, 3, 200)`), |
| 126 | }, |
| 127 | }, |
| 128 | } |
| 129 | |
| 130 | for _, test := range tests { |
| 131 | runEval(test, t) |
| 132 | } |
| 133 | } |