From fc89a65ce70f9ee3f12d09b2709281158374656b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Thu, 24 Nov 2016 16:04:53 +0100 Subject: [PATCH] Improved output of negated literals and added unit test. --- include/anthem/Body.h | 10 ++++------ include/anthem/Head.h | 4 ++-- tests/TestTranslation.cpp | 8 ++++++++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/anthem/Body.h b/include/anthem/Body.h index 37b2648..b0e61d1 100644 --- a/include/anthem/Body.h +++ b/include/anthem/Body.h @@ -87,12 +87,10 @@ struct TermPrintVisitor << argument; } - outputStream << " " << Clingo::AST::BinaryOperator::And << " "; - - if (literal.sign == Clingo::AST::Sign::Negation) - outputStream << Clingo::AST::Sign::Negation << " "; - - outputStream << output::Function(function.name) << "("; + outputStream + << " " << Clingo::AST::BinaryOperator::And << " " + << literal.sign + << output::Function(function.name) << "("; for (auto i = function.arguments.cbegin(); i != function.arguments.cend(); i++) { diff --git a/include/anthem/Head.h b/include/anthem/Head.h index e713b4a..89c296b 100644 --- a/include/anthem/Head.h +++ b/include/anthem/Head.h @@ -222,8 +222,8 @@ struct HeadLiteralPrintSubstitutedVisitor { if (literal.sign == Clingo::AST::Sign::DoubleNegation) throwErrorAtLocation(literal.location, "double-negated literals currently unsupported", context); - else if (literal.sign == Clingo::AST::Sign::Negation) - context.logger.outputStream() << Clingo::AST::Sign::Negation << " "; + + context.logger.outputStream() << literal.sign; literal.data.accept(LiteralPrintSubstitutedVisitor(), literal, context); } diff --git a/tests/TestTranslation.cpp b/tests/TestTranslation.cpp index 66800d4..6dc7267 100644 --- a/tests/TestTranslation.cpp +++ b/tests/TestTranslation.cpp @@ -120,4 +120,12 @@ TEST_CASE("[translation] Rules are translated correctly", "[translation]") 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"); } + + SECTION("single negation") + { + input << "not p(X, 1) :- not q(X, 2)."; + 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"); + } }