From 350f31d0fd0ca47037444fcaaf5d827479a39467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Sat, 8 Apr 2017 18:47:06 +0200 Subject: [PATCH] Added simple unit tests for completion. --- tests/TestCompletion.cpp | 50 ++++++++++++++++++++++++++++++++++++ tests/TestSimplification.cpp | 1 + tests/TestTranslation.cpp | 1 + 3 files changed, 52 insertions(+) create mode 100644 tests/TestCompletion.cpp diff --git a/tests/TestCompletion.cpp b/tests/TestCompletion.cpp new file mode 100644 index 0000000..ab8b95d --- /dev/null +++ b/tests/TestCompletion.cpp @@ -0,0 +1,50 @@ +#include + +#include + +#include +#include + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +TEST_CASE("[completion] Rules are completed", "[completion]") +{ + std::stringstream input; + std::stringstream output; + std::stringstream errors; + + anthem::output::Logger logger(output, errors); + anthem::Context context = {logger, {}}; + context.simplify = true; + context.complete = true; + + SECTION("predicte in single rule head") + { + input << "p :- q."; + anthem::translate("input", input, context); + + REQUIRE(output.str() == "(p <-> q)\n"); + } + + SECTION("predicate in multiple rule heads") + { + input << "p :- q.\n" + "p :- r.\n" + "p :- s."; + anthem::translate("input", input, context); + + REQUIRE(output.str() == "(p <-> (q or r or s))\n"); + } + + SECTION("multiple predicates are correctly separated") + { + input << "p :- s.\n" + "q :- t.\n" + "p :- q.\n" + "r :- t.\n" + "q :- r."; + anthem::translate("input", input, context); + + REQUIRE(output.str() == "(p <-> (s or q))\n(q <-> (t or r))\n(r <-> t)\n"); + } +} diff --git a/tests/TestSimplification.cpp b/tests/TestSimplification.cpp index 32dd22d..f06f311 100644 --- a/tests/TestSimplification.cpp +++ b/tests/TestSimplification.cpp @@ -16,6 +16,7 @@ TEST_CASE("[simplification] Rules are simplified correctly", "[simplification]") anthem::output::Logger logger(output, errors); anthem::Context context = {logger, {}}; context.simplify = true; + context.complete = false; SECTION("example 1") { diff --git a/tests/TestTranslation.cpp b/tests/TestTranslation.cpp index 9146b0d..5c7262c 100644 --- a/tests/TestTranslation.cpp +++ b/tests/TestTranslation.cpp @@ -16,6 +16,7 @@ TEST_CASE("[translation] Rules are translated correctly", "[translation]") anthem::output::Logger logger(output, errors); anthem::Context context = {logger, {}}; context.simplify = false; + context.complete = false; SECTION("simple example 1") {