From 712530150f9156d8561fdb565b53088610f0e3f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Thu, 24 Nov 2016 16:51:17 +0100 Subject: [PATCH] Fixed incorrect output of functions and added unit test. --- src/anthem/output/ClingoOutput.cpp | 2 ++ tests/TestTranslation.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/anthem/output/ClingoOutput.cpp b/src/anthem/output/ClingoOutput.cpp index c9990ee..9571125 100644 --- a/src/anthem/output/ClingoOutput.cpp +++ b/src/anthem/output/ClingoOutput.cpp @@ -180,6 +180,8 @@ ColorStream &operator<<(ColorStream &stream, const Clingo::AST::Function &functi if (function.external) stream << Operator("@"); + stream << output::Function(function.name); + const auto postToken = (isUnaryTuple ? ",)" : ")"); printCollection(stream, function.arguments, "(", ", ", postToken, printIfEmpty); diff --git a/tests/TestTranslation.cpp b/tests/TestTranslation.cpp index 6f92db1..a9cd42f 100644 --- a/tests/TestTranslation.cpp +++ b/tests/TestTranslation.cpp @@ -139,4 +139,12 @@ TEST_CASE("[translation] Rules are translated correctly", "[translation]") " 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"); } + + SECTION("nested functions") + { + input << "p(q(s(t(X1))), u(X2)) :- u(v(w(X2)), z(X1))."; + 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"); + } }