patrick
/
plasp
Archived
1
0
Fork 0

Added unit tests covering predicate signature matching.

This commit is contained in:
Patrick Lühne 2017-06-18 23:30:59 +02:00
parent 60d8b9ba77
commit 9fe489de53
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
2 changed files with 185 additions and 0 deletions

View File

@ -0,0 +1,149 @@
#include <catch.hpp>
#include <experimental/filesystem>
#include <pddlparse/AST.h>
#include <pddlparse/Parse.h>
namespace fs = std::experimental::filesystem;
const pddl::Context::WarningCallback ignoreWarnings = [](const auto &, const auto &){};
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_CASE("[PDDL signature matching] The official PDDL instances are parsed correctly", "[PDDL signature matching]")
{
std::stringstream input;
pddl::Tokenizer tokenizer;
pddl::Context context(std::move(tokenizer), ignoreWarnings);
const auto domainFile = fs::path("data") / "test-cases" / "skeleton.pddl";
context.tokenizer.read(domainFile);
SECTION("directly matching primitive types")
{
input
<< "(:action test :parameters (?x - a1 ?y - a2 ?z - a3) :precondition (p1 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_NOTHROW(pddl::parseDescription(context));
}
SECTION("derived primitive types (direct children)")
{
input
<< "(:action test :parameters (?x - b1 ?y - b2 ?z - b3) :precondition (p1 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_NOTHROW(pddl::parseDescription(context));
}
SECTION("derived primitive types (indirect children)")
{
input
<< "(:action test :parameters (?x - c1 ?y - c2 ?z - c3) :precondition (p1 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_NOTHROW(pddl::parseDescription(context));
}
SECTION("incompatible primitive types")
{
input
<< "(:action test :parameters (?x - a3 ?y - a2 ?z - a3) :precondition (p1 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_THROWS(pddl::parseDescription(context));
}
SECTION("unrelated primitive types")
{
input
<< "(:action test :parameters (?x - b1 ?y - b2 ?z - b1) :precondition (p1 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_THROWS(pddl::parseDescription(context));
}
SECTION("incompatible parent types (1)")
{
input
<< "(:action test :parameters (?x - object ?y - b2 ?z - c3) :precondition (p1 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_THROWS(pddl::parseDescription(context));
}
SECTION("incompatible parent types (2)")
{
input
<< "(:action test :parameters (?x - a1 ?y - a2 ?z - a3) :precondition (p2 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_THROWS(pddl::parseDescription(context));
}
SECTION("matching types with multiple inheritance (1)")
{
input
<< "(:action test :parameters (?x - b1 ?y - b2 ?z - cx) :precondition (p1 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_NOTHROW(pddl::parseDescription(context));
}
SECTION("matching types with multiple inheritance (2)")
{
input
<< "(:action test :parameters (?x - bx ?y - b2 ?z - c3) :precondition (p1 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_NOTHROW(pddl::parseDescription(context));
}
SECTION("“either” type not matching primitive type")
{
input
<< "(:action test :parameters (?x - either (a1 a2) ?y - b2 ?z - c3) :precondition (p1 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_THROWS(pddl::parseDescription(context));
}
SECTION("1-ary “either” type matching primitive type")
{
input
<< "(:action test :parameters (?x - (either a1) ?y - a2 ?z - a3) :precondition (p1 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_NOTHROW(pddl::parseDescription(context));
}
SECTION("“either” type directly matching another “either” type")
{
input
<< "(:action test :parameters (?x - (either a1 a2) ?y ?z - (either b1 b3)) :precondition (p3 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_NOTHROW(pddl::parseDescription(context));
}
SECTION("“either” type matching another “either” type via inheritance")
{
input
<< "(:action test :parameters (?x - (either b1 a2) ?y ?z - (either c1 b3)) :precondition (p3 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_NOTHROW(pddl::parseDescription(context));
}
SECTION("“either” type incompatible with another “either” type")
{
input
<< "(:action test :parameters (?x - (either b1 a2) ?y ?z - (either c2 b3)) :precondition (p3 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_THROWS(pddl::parseDescription(context));
}
SECTION("“either” type compatible with another “either” type via multiple inheritance")
{
input
<< "(:action test :parameters (?x - (either cx c2) ?y ?z - (either cx c3)) :precondition (p3 ?x ?y ?z)))";
context.tokenizer.read("input", input);
CHECK_NOTHROW(pddl::parseDescription(context));
}
SECTION("constants compatible with “either” type via multiple inheritance")
{
input
<< "(:action test :precondition (p3 cbx cb1 cb3)))";
context.tokenizer.read("input", input);
CHECK_NOTHROW(pddl::parseDescription(context));
}
}

View File

@ -0,0 +1,36 @@
(define
(domain skeleton)
(:requirements :typing)
(:types
a1 a2 a3 - object
b1 - a1
b2 - a2
b3 - a3
bx - a1
bx - a2
bx - a3
c1 - b1
c2 - b2
c3 - b3
cx - c1
cx - c2
cx - c3
)
(:predicates
(p1 ?x - a1 ?y - a2 ?z - a3)
(p2 ?x - a1 ?y - b2 ?z - c3)
(p3 ?x - (either a1 a2) ?y ?z - (either b1 b3))
)
(:constants
ca1 - a1
ca2 - a2
ca3 - a3
cb1 - b1
cb2 - b2
cb3 - b3
cbx - bx
cc1 - c1
cc2 - c2
cc3 - c3
ccx - cx
)