Added simple unit tests for completion.

This commit is contained in:
Patrick Lühne 2017-04-08 18:47:06 +02:00
parent ac7a0f6d4c
commit 350f31d0fd
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
3 changed files with 52 additions and 0 deletions

50
tests/TestCompletion.cpp Normal file
View File

@ -0,0 +1,50 @@
#include <catch.hpp>
#include <sstream>
#include <anthem/Context.h>
#include <anthem/Translation.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
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");
}
}

View File

@ -16,6 +16,7 @@ TEST_CASE("[simplification] Rules are simplified correctly", "[simplification]")
anthem::output::Logger logger(output, errors); anthem::output::Logger logger(output, errors);
anthem::Context context = {logger, {}}; anthem::Context context = {logger, {}};
context.simplify = true; context.simplify = true;
context.complete = false;
SECTION("example 1") SECTION("example 1")
{ {

View File

@ -16,6 +16,7 @@ TEST_CASE("[translation] Rules are translated correctly", "[translation]")
anthem::output::Logger logger(output, errors); anthem::output::Logger logger(output, errors);
anthem::Context context = {logger, {}}; anthem::Context context = {logger, {}};
context.simplify = false; context.simplify = false;
context.complete = false;
SECTION("simple example 1") SECTION("simple example 1")
{ {