2017-03-23 15:10:51 +01:00
|
|
|
#include <catch.hpp>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
2017-05-30 03:53:51 +02:00
|
|
|
#include <anthem/AST.h>
|
2017-03-23 15:10:51 +01:00
|
|
|
#include <anthem/Context.h>
|
|
|
|
#include <anthem/Translation.h>
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-05-30 04:06:56 +02:00
|
|
|
TEST_CASE("[simplification] Rules are simplified correctly", "[simplification]")
|
2017-03-23 15:10:51 +01:00
|
|
|
{
|
|
|
|
std::stringstream input;
|
|
|
|
std::stringstream output;
|
|
|
|
std::stringstream errors;
|
|
|
|
|
|
|
|
anthem::output::Logger logger(output, errors);
|
2017-05-30 04:06:56 +02:00
|
|
|
anthem::Context context(std::move(logger));
|
2017-06-06 01:44:44 +02:00
|
|
|
context.performSimplification = true;
|
|
|
|
context.performCompletion = false;
|
2017-03-23 15:10:51 +01:00
|
|
|
|
|
|
|
SECTION("example 1")
|
|
|
|
{
|
|
|
|
input << ":- in(I, S), in(J, S), in(I + J, S).";
|
2017-04-10 16:32:12 +02:00
|
|
|
anthem::translate("input", input, context);
|
2017-03-23 15:10:51 +01:00
|
|
|
|
2017-05-30 04:06:56 +02:00
|
|
|
CHECK(output.str() == "((in(U1, U2) and in(U3, U2) and exists X1 (X1 in (U1 + U3) and in(X1, U2))) -> #false)\n");
|
2017-03-23 15:10:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("example 2")
|
|
|
|
{
|
|
|
|
input << "covered(I) :- in(I, S).";
|
2017-04-10 16:32:12 +02:00
|
|
|
anthem::translate("input", input, context);
|
2017-03-23 15:10:51 +01:00
|
|
|
|
2017-05-30 04:06:56 +02:00
|
|
|
CHECK(output.str() == "((V1 = U1 and in(U1, U2)) -> covered(V1))\n");
|
2017-03-23 15:10:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("example 3")
|
|
|
|
{
|
|
|
|
input << ":- not covered(I), I = 1..n.";
|
2017-04-10 16:32:12 +02:00
|
|
|
anthem::translate("input", input, context);
|
2017-03-23 15:10:51 +01:00
|
|
|
|
2017-05-30 04:06:56 +02:00
|
|
|
CHECK(output.str() == "((not covered(U1) and U1 in 1..n) -> #false)\n");
|
2017-03-23 15:10:51 +01:00
|
|
|
}
|
2017-03-28 17:10:38 +02:00
|
|
|
|
|
|
|
SECTION("comparisons")
|
|
|
|
{
|
|
|
|
input << ":- M > N.";
|
2017-04-10 16:32:12 +02:00
|
|
|
anthem::translate("input", input, context);
|
2017-03-28 17:10:38 +02:00
|
|
|
|
2017-05-30 04:06:56 +02:00
|
|
|
CHECK(output.str() == "(U1 > U2 -> #false)\n");
|
2017-03-28 17:10:38 +02:00
|
|
|
}
|
2018-05-03 16:57:19 +02:00
|
|
|
|
|
|
|
SECTION("biconditionals are replaced with implifactions with choice rules")
|
|
|
|
{
|
|
|
|
context.performCompletion = true;
|
|
|
|
|
|
|
|
input << "{p(a)}.";
|
|
|
|
anthem::translate("input", input, context);
|
|
|
|
|
|
|
|
CHECK(output.str() == "forall V1 (p(V1) -> V1 = a)\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("biconditionals are replaced with implifactions with complicated choice rules")
|
|
|
|
{
|
|
|
|
context.performCompletion = true;
|
|
|
|
|
|
|
|
input << "{p(n + 5)}.";
|
|
|
|
anthem::translate("input", input, context);
|
|
|
|
|
|
|
|
CHECK(output.str() == "forall V1 (p(V1) -> V1 in (n + 5))\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("biconditionals are not replaced with implifactions with nonchoice rules")
|
|
|
|
{
|
|
|
|
context.performCompletion = true;
|
|
|
|
|
|
|
|
input << "p(a).";
|
|
|
|
anthem::translate("input", input, context);
|
|
|
|
|
|
|
|
CHECK(output.str() == "forall V1 (p(V1) <-> V1 = a)\n");
|
|
|
|
}
|
2017-03-23 15:10:51 +01:00
|
|
|
}
|