2017-04-08 18:47:06 +02:00
|
|
|
#include <catch.hpp>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
2017-05-30 03:53:51 +02:00
|
|
|
#include <anthem/AST.h>
|
2017-04-08 18:47:06 +02:00
|
|
|
#include <anthem/Context.h>
|
|
|
|
#include <anthem/Translation.h>
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-05-30 03:53:51 +02:00
|
|
|
/*TEST_CASE("[completion] Rules are completed", "[completion]")
|
2017-04-08 18:47:06 +02:00
|
|
|
{
|
|
|
|
std::stringstream input;
|
|
|
|
std::stringstream output;
|
|
|
|
std::stringstream errors;
|
|
|
|
|
|
|
|
anthem::output::Logger logger(output, errors);
|
2017-05-31 18:03:19 +02:00
|
|
|
anthem::Context context(std::move(logger));
|
2017-04-08 18:47:06 +02:00
|
|
|
context.simplify = true;
|
|
|
|
context.complete = true;
|
|
|
|
|
2017-04-10 14:30:35 +02:00
|
|
|
SECTION("predicate in single rule head")
|
2017-04-08 18:47:06 +02:00
|
|
|
{
|
|
|
|
input << "p :- q.";
|
2017-04-10 16:32:12 +02:00
|
|
|
anthem::translate("input", input, context);
|
2017-04-08 18:47:06 +02:00
|
|
|
|
2017-04-10 16:32:12 +02:00
|
|
|
CHECK(output.str() ==
|
|
|
|
"(p <-> q)\n"
|
|
|
|
"not q\n");
|
2017-04-08 18:47:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("predicate in multiple rule heads")
|
|
|
|
{
|
2017-04-10 16:32:12 +02:00
|
|
|
input <<
|
|
|
|
"p :- q.\n"
|
2017-04-08 18:47:06 +02:00
|
|
|
"p :- r.\n"
|
|
|
|
"p :- s.";
|
2017-04-10 16:32:12 +02:00
|
|
|
anthem::translate("input", input, context);
|
2017-04-08 18:47:06 +02:00
|
|
|
|
2017-04-10 16:32:12 +02:00
|
|
|
CHECK(output.str() ==
|
|
|
|
"(p <-> (q or r or s))\n"
|
|
|
|
"not q\n"
|
|
|
|
"not r\n"
|
|
|
|
"not s\n");
|
2017-04-08 18:47:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("multiple predicates are correctly separated")
|
|
|
|
{
|
2017-04-10 16:32:12 +02:00
|
|
|
input <<
|
|
|
|
"p :- s.\n"
|
2017-04-08 18:47:06 +02:00
|
|
|
"q :- t.\n"
|
|
|
|
"p :- q.\n"
|
|
|
|
"r :- t.\n"
|
|
|
|
"q :- r.";
|
2017-04-10 16:32:12 +02:00
|
|
|
anthem::translate("input", input, context);
|
|
|
|
|
|
|
|
CHECK(output.str() ==
|
|
|
|
"(p <-> (s or q))\n"
|
|
|
|
"(q <-> (t or r))\n"
|
|
|
|
"(r <-> t)\n"
|
|
|
|
"not s\n"
|
|
|
|
"not t\n");
|
2017-04-08 18:47:06 +02:00
|
|
|
}
|
2017-04-08 18:50:42 +02:00
|
|
|
|
|
|
|
SECTION("integrity constraints")
|
|
|
|
{
|
2017-04-10 16:32:12 +02:00
|
|
|
input <<
|
|
|
|
":- q.\n"
|
|
|
|
":- r(5).\n"
|
|
|
|
":- s(N).\n"
|
2017-04-08 20:02:20 +02:00
|
|
|
"#false :- t.\n"
|
2017-04-10 16:32:12 +02:00
|
|
|
"#false :- u(5).";
|
|
|
|
anthem::translate("input", input, context);
|
|
|
|
|
|
|
|
CHECK(output.str() ==
|
|
|
|
"not q\n"
|
|
|
|
"forall V1 not r(V1)\n"
|
|
|
|
"forall V1 not s(V1)\n"
|
|
|
|
"not t\n"
|
|
|
|
"forall V1 not u(V1)\n"
|
|
|
|
"not q\n"
|
|
|
|
"not r(5)\n"
|
|
|
|
"forall N not s(N)\n"
|
|
|
|
"not t\n"
|
|
|
|
"not u(5)\n");
|
|
|
|
}
|
2017-04-08 18:50:42 +02:00
|
|
|
|
2017-04-10 16:32:12 +02:00
|
|
|
SECTION("Booleans")
|
|
|
|
{
|
|
|
|
input <<
|
|
|
|
"#true :- #true.\n"
|
|
|
|
"#true :- #false.\n"
|
|
|
|
"#false :- #true.\n"
|
|
|
|
"#false :- #false.\n";
|
|
|
|
anthem::translate("input", input, context);
|
|
|
|
|
|
|
|
CHECK(output.str() ==
|
|
|
|
"not #true\n"
|
|
|
|
"not #false\n");
|
2017-04-08 18:50:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("facts")
|
|
|
|
{
|
2017-04-10 16:32:12 +02:00
|
|
|
input <<
|
|
|
|
"q.\n"
|
2017-04-08 19:59:59 +02:00
|
|
|
"r.\n"
|
2017-04-10 16:32:12 +02:00
|
|
|
"s :- #true.\n"
|
|
|
|
"t :- #true.";
|
|
|
|
anthem::translate("input", input, context);
|
|
|
|
|
|
|
|
CHECK(output.str() ==
|
|
|
|
"q\n"
|
|
|
|
"r\n"
|
|
|
|
"s\n"
|
|
|
|
"t\n");
|
2017-04-08 18:50:42 +02:00
|
|
|
}
|
2017-04-08 20:17:01 +02:00
|
|
|
|
|
|
|
SECTION("useless implications")
|
|
|
|
{
|
2017-04-10 16:32:12 +02:00
|
|
|
input <<
|
|
|
|
"#true :- p, q(N), t(1, 2).\n"
|
2017-04-08 20:17:01 +02:00
|
|
|
"#true.\n"
|
2017-04-10 16:32:12 +02:00
|
|
|
"v :- #false.";
|
|
|
|
anthem::translate("input", input, context);
|
2017-04-08 20:17:01 +02:00
|
|
|
|
2017-04-10 16:32:12 +02:00
|
|
|
CHECK(output.str() ==
|
|
|
|
"not p\n"
|
|
|
|
"forall V1 not q(V1)\n"
|
|
|
|
"forall V1, V2 not t(V1, V2)\n"
|
|
|
|
"not v\n");
|
2017-04-08 20:17:01 +02:00
|
|
|
}
|
|
|
|
|
2017-04-08 20:22:50 +02:00
|
|
|
SECTION("example")
|
|
|
|
{
|
2017-04-10 16:32:12 +02:00
|
|
|
input <<
|
|
|
|
"{in(1..n, 1..r)}.\n"
|
2017-04-08 20:22:50 +02:00
|
|
|
"covered(I) :- in(I, S).\n"
|
|
|
|
":- I = 1..n, not covered(I).\n"
|
|
|
|
":- in(I, S), in(J, S), in(I + J, S).";
|
2017-04-10 16:32:12 +02:00
|
|
|
anthem::translate("input", input, context);
|
2017-04-08 20:22:50 +02:00
|
|
|
|
2017-04-10 16:32:12 +02:00
|
|
|
CHECK(output.str() ==
|
2017-04-08 20:22:50 +02:00
|
|
|
"forall V1 (covered(V1) <-> exists I, S (V1 = I and in(I, S)))\n"
|
2017-04-10 16:32:12 +02:00
|
|
|
"forall V1, V2 (in(V1, V2) <-> (V1 in 1..n and V2 in 1..r and in(V1, V2)))\n"
|
2017-04-08 20:22:50 +02:00
|
|
|
"forall I not (I in 1..n and not covered(I))\n"
|
|
|
|
"forall I, S, J not (in(I, S) and in(J, S) and exists X5 (X5 in (I + J) and in(X5, S)))\n");
|
|
|
|
}
|
|
|
|
|
2017-04-08 20:17:01 +02:00
|
|
|
// TODO: test collecting free variables
|
2017-04-08 18:47:06 +02:00
|
|
|
}
|
2017-05-30 03:53:51 +02:00
|
|
|
*/
|