2017-03-23 15:10:51 +01:00
|
|
|
#include <catch.hpp>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <anthem/Context.h>
|
|
|
|
#include <anthem/Translation.h>
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-04-08 18:42:36 +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);
|
|
|
|
anthem::Context context = {logger, {}};
|
|
|
|
context.simplify = true;
|
2017-04-08 18:47:06 +02:00
|
|
|
context.complete = 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-08 19:59:59 +02:00
|
|
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
2017-03-23 15:10:51 +01:00
|
|
|
|
2017-04-08 19:59:59 +02:00
|
|
|
CHECK(output.str() == "((in(I, S) and in(J, S) and exists X5 (X5 in (I + J) and in(X5, S))) -> #false)\n");
|
2017-03-23 15:10:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("example 2")
|
|
|
|
{
|
|
|
|
input << "covered(I) :- in(I, S).";
|
2017-04-08 19:59:59 +02:00
|
|
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
2017-03-23 15:10:51 +01:00
|
|
|
|
2017-04-08 19:59:59 +02:00
|
|
|
CHECK(output.str() == "((V1 = I and in(I, S)) -> covered(V1))\n");
|
2017-03-23 15:10:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("example 3")
|
|
|
|
{
|
|
|
|
input << ":- not covered(I), I = 1..n.";
|
2017-04-08 19:59:59 +02:00
|
|
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
2017-03-23 15:10:51 +01:00
|
|
|
|
2017-04-08 19:59:59 +02:00
|
|
|
CHECK(output.str() == "((not covered(I) and I 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-08 19:59:59 +02:00
|
|
|
REQUIRE_NOTHROW(anthem::translate("input", input, context));
|
2017-03-28 17:10:38 +02:00
|
|
|
|
2017-04-08 19:59:59 +02:00
|
|
|
CHECK(output.str() == "(M > N -> #false)\n");
|
2017-03-28 17:10:38 +02:00
|
|
|
}
|
2017-03-23 15:10:51 +01:00
|
|
|
}
|