Enforcing unit tests not to throw exceptions.
This commit is contained in:
parent
a1648e27c9
commit
2ae5cfbfa6
@ -21,9 +21,9 @@ TEST_CASE("[completion] Rules are completed", "[completion]")
|
|||||||
SECTION("predicte in single rule head")
|
SECTION("predicte in single rule head")
|
||||||
{
|
{
|
||||||
input << "p :- q.";
|
input << "p :- q.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "(p <-> q)\n");
|
CHECK(output.str() == "(p <-> q)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("predicate in multiple rule heads")
|
SECTION("predicate in multiple rule heads")
|
||||||
@ -31,9 +31,9 @@ TEST_CASE("[completion] Rules are completed", "[completion]")
|
|||||||
input << "p :- q.\n"
|
input << "p :- q.\n"
|
||||||
"p :- r.\n"
|
"p :- r.\n"
|
||||||
"p :- s.";
|
"p :- s.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "(p <-> (q or r or s))\n");
|
CHECK(output.str() == "(p <-> (q or r or s))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("multiple predicates are correctly separated")
|
SECTION("multiple predicates are correctly separated")
|
||||||
@ -43,26 +43,30 @@ TEST_CASE("[completion] Rules are completed", "[completion]")
|
|||||||
"p :- q.\n"
|
"p :- q.\n"
|
||||||
"r :- t.\n"
|
"r :- t.\n"
|
||||||
"q :- r.";
|
"q :- r.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "(p <-> (s or q))\n(q <-> (t or r))\n(r <-> t)\n");
|
CHECK(output.str() == "(p <-> (s or q))\n(q <-> (t or r))\n(r <-> t)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("integrity constraints")
|
SECTION("integrity constraints")
|
||||||
{
|
{
|
||||||
input << ":- q.\n"
|
input << ":- q.\n"
|
||||||
":- s(5).";
|
":- s(5).\n"
|
||||||
anthem::translate("input", input, context);
|
"#false :- t\n"
|
||||||
|
"#false :- v(5).";
|
||||||
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "not q\nnot s(5)\n");
|
CHECK(output.str() == "not q\nnot s(5)\nnot t\nnot v(5)");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("facts")
|
SECTION("facts")
|
||||||
{
|
{
|
||||||
input << "q.\n"
|
input << "q.\n"
|
||||||
"r.";
|
"r.\n"
|
||||||
anthem::translate("input", input, context);
|
"t :- #true.\n"
|
||||||
|
"s :- #true.";
|
||||||
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "(q <-> #true)\n(r <-> #true)\n");
|
CHECK(output.str() == "q\nr\nt\ns\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,32 +21,32 @@ TEST_CASE("[simplification] Rules are simplified correctly", "[simplification]")
|
|||||||
SECTION("example 1")
|
SECTION("example 1")
|
||||||
{
|
{
|
||||||
input << ":- in(I, S), in(J, S), in(I + J, S).";
|
input << ":- in(I, S), in(J, S), in(I + J, S).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((in(I, S) and in(J, S) and exists X5 (X5 in (I + J) and in(X5, S))) -> #false)\n");
|
CHECK(output.str() == "((in(I, S) and in(J, S) and exists X5 (X5 in (I + J) and in(X5, S))) -> #false)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("example 2")
|
SECTION("example 2")
|
||||||
{
|
{
|
||||||
input << "covered(I) :- in(I, S).";
|
input << "covered(I) :- in(I, S).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 = I and in(I, S)) -> covered(V1))\n");
|
CHECK(output.str() == "((V1 = I and in(I, S)) -> covered(V1))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("example 3")
|
SECTION("example 3")
|
||||||
{
|
{
|
||||||
input << ":- not covered(I), I = 1..n.";
|
input << ":- not covered(I), I = 1..n.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((not covered(I) and I in 1..n) -> #false)\n");
|
CHECK(output.str() == "((not covered(I) and I in 1..n) -> #false)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("comparisons")
|
SECTION("comparisons")
|
||||||
{
|
{
|
||||||
input << ":- M > N.";
|
input << ":- M > N.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "(M > N -> #false)\n");
|
CHECK(output.str() == "(M > N -> #false)\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,188 +21,188 @@ TEST_CASE("[translation] Rules are translated correctly", "[translation]")
|
|||||||
SECTION("simple example 1")
|
SECTION("simple example 1")
|
||||||
{
|
{
|
||||||
input << "p(1..5).";
|
input << "p(1..5).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "(V1 in 1..5 -> p(V1))\n");
|
CHECK(output.str() == "(V1 in 1..5 -> p(V1))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("simple example 2")
|
SECTION("simple example 2")
|
||||||
{
|
{
|
||||||
input << "p(N) :- N = 1..5.";
|
input << "p(N) :- N = 1..5.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in N and exists X1, X2 (X1 in N and X2 in 1..5 and X1 = X2)) -> p(V1))\n");
|
CHECK(output.str() == "((V1 in N and exists X1, X2 (X1 in N and X2 in 1..5 and X1 = X2)) -> p(V1))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("simple example 3")
|
SECTION("simple example 3")
|
||||||
{
|
{
|
||||||
input << "p(N + 1) :- q(N).";
|
input << "p(N + 1) :- q(N).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in (N + 1) and exists X1 (X1 in N and q(X1))) -> p(V1))\n");
|
CHECK(output.str() == "((V1 in (N + 1) and exists X1 (X1 in N and q(X1))) -> p(V1))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("n-ary head")
|
SECTION("n-ary head")
|
||||||
{
|
{
|
||||||
input << "p(N, 1, 2) :- N = 1..5.";
|
input << "p(N, 1, 2) :- N = 1..5.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in N and V2 in 1 and V3 in 2 and exists X1, X2 (X1 in N and X2 in 1..5 and X1 = X2)) -> p(V1, V2, V3))\n");
|
CHECK(output.str() == "((V1 in N and V2 in 1 and V3 in 2 and exists X1, X2 (X1 in N and X2 in 1..5 and X1 = X2)) -> p(V1, V2, V3))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("disjunctive head")
|
SECTION("disjunctive head")
|
||||||
{
|
{
|
||||||
// TODO: check why order of disjunctive literals is inverted
|
// TODO: check why order of disjunctive literals is inverted
|
||||||
input << "q(3, N); p(N, 1, 2) :- N = 1..5.";
|
input << "q(3, N); p(N, 1, 2) :- N = 1..5.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in N and V2 in 1 and V3 in 2 and V4 in 3 and V5 in N and exists X1, X2 (X1 in N and X2 in 1..5 and X1 = X2)) -> (p(V1, V2, V3) or q(V4, V5)))\n");
|
CHECK(output.str() == "((V1 in N and V2 in 1 and V3 in 2 and V4 in 3 and V5 in N and exists X1, X2 (X1 in N and X2 in 1..5 and X1 = X2)) -> (p(V1, V2, V3) or q(V4, V5)))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("disjunctive head (alternative syntax)")
|
SECTION("disjunctive head (alternative syntax)")
|
||||||
{
|
{
|
||||||
// TODO: check why order of disjunctive literals is inverted
|
// TODO: check why order of disjunctive literals is inverted
|
||||||
input << "q(3, N), p(N, 1, 2) :- N = 1..5.";
|
input << "q(3, N), p(N, 1, 2) :- N = 1..5.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in N and V2 in 1 and V3 in 2 and V4 in 3 and V5 in N and exists X1, X2 (X1 in N and X2 in 1..5 and X1 = X2)) -> (p(V1, V2, V3) or q(V4, V5)))\n");
|
CHECK(output.str() == "((V1 in N and V2 in 1 and V3 in 2 and V4 in 3 and V5 in N and exists X1, X2 (X1 in N and X2 in 1..5 and X1 = X2)) -> (p(V1, V2, V3) or q(V4, V5)))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("escaping conflicting variable names")
|
SECTION("escaping conflicting variable names")
|
||||||
{
|
{
|
||||||
input << "p(X1, V1, A1) :- q(X1), q(V1), q(A1).";
|
input << "p(X1, V1, A1) :- q(X1), q(V1), q(A1).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in _X1 and V2 in _V1 and V3 in _A1 and exists X1 (X1 in _X1 and q(X1)) and exists X2 (X2 in _V1 and q(X2)) and exists X3 (X3 in _A1 and q(X3))) -> p(V1, V2, V3))\n");
|
CHECK(output.str() == "((V1 in _X1 and V2 in _V1 and V3 in _A1 and exists X1 (X1 in _X1 and q(X1)) and exists X2 (X2 in _V1 and q(X2)) and exists X3 (X3 in _A1 and q(X3))) -> p(V1, V2, V3))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("fact")
|
SECTION("fact")
|
||||||
{
|
{
|
||||||
input << "p(42).";
|
input << "p(42).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "(V1 in 42 -> p(V1))\n");
|
CHECK(output.str() == "(V1 in 42 -> p(V1))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("0-ary fact")
|
SECTION("0-ary fact")
|
||||||
{
|
{
|
||||||
input << "p.";
|
input << "p.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "(#true -> p)\n");
|
CHECK(output.str() == "(#true -> p)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("function")
|
SECTION("function")
|
||||||
{
|
{
|
||||||
input << ":- not p(I), I = 1..n.";
|
input << ":- not p(I), I = 1..n.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((exists X1 (X1 in I and not p(X1)) and exists X2, X3 (X2 in I and X3 in 1..n and X2 = X3)) -> #false)\n");
|
CHECK(output.str() == "((exists X1 (X1 in I and not p(X1)) and exists X2, X3 (X2 in I and X3 in 1..n and X2 = X3)) -> #false)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("disjunctive fact (no arguments)")
|
SECTION("disjunctive fact (no arguments)")
|
||||||
{
|
{
|
||||||
input << "q; p.";
|
input << "q; p.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "(#true -> (p or q))\n");
|
CHECK(output.str() == "(#true -> (p or q))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("disjunctive fact (arguments)")
|
SECTION("disjunctive fact (arguments)")
|
||||||
{
|
{
|
||||||
input << "q; p(42).";
|
input << "q; p(42).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "(V1 in 42 -> (p(V1) or q))\n");
|
CHECK(output.str() == "(V1 in 42 -> (p(V1) or q))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("integrity constraint (no arguments)")
|
SECTION("integrity constraint (no arguments)")
|
||||||
{
|
{
|
||||||
input << ":- p, q.";
|
input << ":- p, q.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((p and q) -> #false)\n");
|
CHECK(output.str() == "((p and q) -> #false)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("contradiction")
|
SECTION("contradiction")
|
||||||
{
|
{
|
||||||
input << ":-.";
|
input << ":-.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "(#true -> #false)\n");
|
CHECK(output.str() == "(#true -> #false)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("integrity constraint (arguments)")
|
SECTION("integrity constraint (arguments)")
|
||||||
{
|
{
|
||||||
input << ":- p(42), q.";
|
input << ":- p(42), q.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((exists X1 (X1 in 42 and p(X1)) and q) -> #false)\n");
|
CHECK(output.str() == "((exists X1 (X1 in 42 and p(X1)) and q) -> #false)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("inf/sup")
|
SECTION("inf/sup")
|
||||||
{
|
{
|
||||||
input << "p(X, #inf) :- q(X, #sup).";
|
input << "p(X, #inf) :- q(X, #sup).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in X and V2 in #inf and exists X1, X2 (X1 in X and X2 in #sup and q(X1, X2))) -> p(V1, V2))\n");
|
CHECK(output.str() == "((V1 in X and V2 in #inf and exists X1, X2 (X1 in X and X2 in #sup and q(X1, X2))) -> p(V1, V2))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("strings")
|
SECTION("strings")
|
||||||
{
|
{
|
||||||
input << "p(X, \"foo\") :- q(X, \"bar\").";
|
input << "p(X, \"foo\") :- q(X, \"bar\").";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in X and V2 in \"foo\" and exists X1, X2 (X1 in X and X2 in \"bar\" and q(X1, X2))) -> p(V1, V2))\n");
|
CHECK(output.str() == "((V1 in X and V2 in \"foo\" and exists X1, X2 (X1 in X and X2 in \"bar\" and q(X1, X2))) -> p(V1, V2))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("tuples")
|
SECTION("tuples")
|
||||||
{
|
{
|
||||||
input << "p(X, (1, 2, 3)) :- q(X, (4, 5)).";
|
input << "p(X, (1, 2, 3)) :- q(X, (4, 5)).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in X and V2 in (1, 2, 3) and exists X1, X2 (X1 in X and X2 in (4, 5) and q(X1, X2))) -> p(V1, V2))\n");
|
CHECK(output.str() == "((V1 in X and V2 in (1, 2, 3) and exists X1, X2 (X1 in X and X2 in (4, 5) and q(X1, X2))) -> p(V1, V2))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("1-ary tuples")
|
SECTION("1-ary tuples")
|
||||||
{
|
{
|
||||||
input << "p(X, (1,)) :- q(X, (2,)).";
|
input << "p(X, (1,)) :- q(X, (2,)).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in X and V2 in (1,) and exists X1, X2 (X1 in X and X2 in (2,) and q(X1, X2))) -> p(V1, V2))\n");
|
CHECK(output.str() == "((V1 in X and V2 in (1,) and exists X1, X2 (X1 in X and X2 in (2,) and q(X1, X2))) -> p(V1, V2))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("intervals")
|
SECTION("intervals")
|
||||||
{
|
{
|
||||||
input << "p(X, 1..10) :- q(X, 6..12).";
|
input << "p(X, 1..10) :- q(X, 6..12).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in X and V2 in 1..10 and exists X1, X2 (X1 in X and X2 in 6..12 and q(X1, X2))) -> p(V1, V2))\n");
|
CHECK(output.str() == "((V1 in X and V2 in 1..10 and exists X1, X2 (X1 in X and X2 in 6..12 and q(X1, X2))) -> p(V1, V2))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("comparisons")
|
SECTION("comparisons")
|
||||||
{
|
{
|
||||||
input << "p(M, N, O, P) :- M < N, P != O.";
|
input << "p(M, N, O, P) :- M < N, P != O.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in M and V2 in N and V3 in O and V4 in P and exists X1, X2 (X1 in M and X2 in N and X1 < X2) and exists X3, X4 (X3 in P and X4 in O and X3 != X4)) -> p(V1, V2, V3, V4))\n");
|
CHECK(output.str() == "((V1 in M and V2 in N and V3 in O and V4 in P and exists X1, X2 (X1 in M and X2 in N and X1 < X2) and exists X3, X4 (X3 in P and X4 in O and X3 != X4)) -> p(V1, V2, V3, V4))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("single negation")
|
SECTION("single negation")
|
||||||
{
|
{
|
||||||
input << "not p(X, 1) :- not q(X, 2).";
|
input << "not p(X, 1) :- not q(X, 2).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in X and V2 in 1 and exists X1, X2 (X1 in X and X2 in 2 and not q(X1, X2))) -> not p(V1, V2))\n");
|
CHECK(output.str() == "((V1 in X and V2 in 1 and exists X1, X2 (X1 in X and X2 in 2 and not q(X1, X2))) -> not p(V1, V2))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("variable numbering")
|
SECTION("variable numbering")
|
||||||
{
|
{
|
||||||
// TODO: check why order of disjunctive literals is inverted
|
// TODO: check why order of disjunctive literals is inverted
|
||||||
input << "f; q(A1, A2); p(A3, r(A4)); g(g(A5)) :- g(A3), f, q(A4, A1), p(A2, A5).";
|
input << "f; q(A1, A2); p(A3, r(A4)); g(g(A5)) :- g(A3), f, q(A4, A1), p(A2, A5).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in _A1 and V2 in _A2 and V3 in _A3 and V4 in r(_A4) and V5 in g(_A5)"
|
CHECK(output.str() == "((V1 in _A1 and V2 in _A2 and V3 in _A3 and V4 in r(_A4) and V5 in g(_A5)"
|
||||||
" and exists X1 (X1 in _A3 and g(X1)) and f and exists X2, X3 (X2 in _A4 and X3 in _A1 and q(X2, X3)) and exists X4, X5 (X4 in _A2 and X5 in _A5 and p(X4, X5)))"
|
" and exists X1 (X1 in _A3 and g(X1)) and f and exists X2, X3 (X2 in _A4 and X3 in _A1 and q(X2, X3)) and exists X4, X5 (X4 in _A2 and X5 in _A5 and p(X4, X5)))"
|
||||||
" -> (q(V1, V2) or p(V3, V4) or g(V5) or f))\n");
|
" -> (q(V1, V2) or p(V3, V4) or g(V5) or f))\n");
|
||||||
}
|
}
|
||||||
@ -210,64 +210,64 @@ TEST_CASE("[translation] Rules are translated correctly", "[translation]")
|
|||||||
SECTION("nested functions")
|
SECTION("nested functions")
|
||||||
{
|
{
|
||||||
input << "p(q(s(t(X1))), u(X2)) :- u(v(w(X2)), z(X1)).";
|
input << "p(q(s(t(X1))), u(X2)) :- u(v(w(X2)), z(X1)).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in q(s(t(_X1))) and V2 in u(_X2) and exists X1, X2 (X1 in v(w(_X2)) and X2 in z(_X1) and u(X1, X2))) -> p(V1, V2))\n");
|
CHECK(output.str() == "((V1 in q(s(t(_X1))) and V2 in u(_X2) and exists X1, X2 (X1 in v(w(_X2)) and X2 in z(_X1) and u(X1, X2))) -> p(V1, V2))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("choice rule (simple)")
|
SECTION("choice rule (simple)")
|
||||||
{
|
{
|
||||||
input << "{p}.";
|
input << "{p}.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "(p -> p)\n");
|
CHECK(output.str() == "(p -> p)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("choice rule (two elements)")
|
SECTION("choice rule (two elements)")
|
||||||
{
|
{
|
||||||
input << "{p; q}.";
|
input << "{p; q}.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "(p -> p)\n(q -> q)\n");
|
CHECK(output.str() == "(p -> p)\n(q -> q)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("choice rule (n-ary elements)")
|
SECTION("choice rule (n-ary elements)")
|
||||||
{
|
{
|
||||||
input << "{p(1..3, N); q(2..4)}.";
|
input << "{p(1..3, N); q(2..4)}.";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in 1..3 and V2 in N and V3 in 2..4 and p(V1, V2)) -> p(V1, V2))\n((V1 in 1..3 and V2 in N and V3 in 2..4 and q(V3)) -> q(V3))\n");
|
CHECK(output.str() == "((V1 in 1..3 and V2 in N and V3 in 2..4 and p(V1, V2)) -> p(V1, V2))\n((V1 in 1..3 and V2 in N and V3 in 2..4 and q(V3)) -> q(V3))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("choice rule with body")
|
SECTION("choice rule with body")
|
||||||
{
|
{
|
||||||
input << "{p(M, N); q(P)} :- s(M, N, P).";
|
input << "{p(M, N); q(P)} :- s(M, N, P).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in M and V2 in N and V3 in P and exists X1, X2, X3 (X1 in M and X2 in N and X3 in P and s(X1, X2, X3)) and p(V1, V2)) -> p(V1, V2))\n((V1 in M and V2 in N and V3 in P and exists X1, X2, X3 (X1 in M and X2 in N and X3 in P and s(X1, X2, X3)) and q(V3)) -> q(V3))\n");
|
CHECK(output.str() == "((V1 in M and V2 in N and V3 in P and exists X1, X2, X3 (X1 in M and X2 in N and X3 in P and s(X1, X2, X3)) and p(V1, V2)) -> p(V1, V2))\n((V1 in M and V2 in N and V3 in P and exists X1, X2, X3 (X1 in M and X2 in N and X3 in P and s(X1, X2, X3)) and q(V3)) -> q(V3))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("choice rule with negation")
|
SECTION("choice rule with negation")
|
||||||
{
|
{
|
||||||
input << "{not p(X, 1)} :- not q(X, 2).";
|
input << "{not p(X, 1)} :- not q(X, 2).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in X and V2 in 1 and exists X1, X2 (X1 in X and X2 in 2 and not q(X1, X2)) and not p(V1, V2)) -> not p(V1, V2))\n");
|
CHECK(output.str() == "((V1 in X and V2 in 1 and exists X1, X2 (X1 in X and X2 in 2 and not q(X1, X2)) and not p(V1, V2)) -> not p(V1, V2))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("choice rule with negation (two elements)")
|
SECTION("choice rule with negation (two elements)")
|
||||||
{
|
{
|
||||||
input << "{not p(X, 1); not s} :- not q(X, 2).";
|
input << "{not p(X, 1); not s} :- not q(X, 2).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in X and V2 in 1 and exists X1, X2 (X1 in X and X2 in 2 and not q(X1, X2)) and not p(V1, V2)) -> not p(V1, V2))\n((V1 in X and V2 in 1 and exists X1, X2 (X1 in X and X2 in 2 and not q(X1, X2)) and not s) -> not s)\n");
|
CHECK(output.str() == "((V1 in X and V2 in 1 and exists X1, X2 (X1 in X and X2 in 2 and not q(X1, X2)) and not p(V1, V2)) -> not p(V1, V2))\n((V1 in X and V2 in 1 and exists X1, X2 (X1 in X and X2 in 2 and not q(X1, X2)) and not s) -> not s)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("anonymous variables")
|
SECTION("anonymous variables")
|
||||||
{
|
{
|
||||||
input << "p(_, _) :- q(_, _).";
|
input << "p(_, _) :- q(_, _).";
|
||||||
anthem::translate("input", input, context);
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
||||||
|
|
||||||
REQUIRE(output.str() == "((V1 in A1 and V2 in A2 and exists X1, X2 (X1 in A3 and X2 in A4 and q(X1, X2))) -> p(V1, V2))\n");
|
CHECK(output.str() == "((V1 in A1 and V2 in A2 and exists X1, X2 (X1 in A3 and X2 in A4 and q(X1, X2))) -> p(V1, V2))\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user