patrick
/
plasp
Archived
1
0
Fork 0

Added tests for derived predicate numbering.

These tests ensure that derived predicates are numbered correctly,
whether they are introduced by the domain, the problem, or both.
This commit is contained in:
Patrick Lühne 2017-11-16 17:30:53 +01:00
parent 39410ac98b
commit 5af0c26650
No known key found for this signature in database
GPG Key ID: 05F3611E97A70ABF
4 changed files with 172 additions and 0 deletions

View File

@ -429,3 +429,67 @@ TEST_CASE("[normalization] Nested expressions are correctly flattened via derive
CHECK(a31212->arguments[1].get<pddl::normalizedAST::VariablePointer>()->declaration == a312->declaration->existentialParameters[0].get());
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_CASE("[normalization] Derived predicates are correctly numbered", "[normalization]")
{
pddl::Tokenizer tokenizer;
pddl::Context context(std::move(tokenizer), ignoreWarnings);
SECTION("derived predicates introduced by both domain and problem")
{
const auto domainFile = fs::path("data") / "normalization" / "normalization-6-1.pddl";
context.tokenizer.read(domainFile);
auto description = pddl::parseDescription(context);
const auto normalizedDescription = pddl::normalize(std::move(description));
const auto &domain = normalizedDescription.domain;
const auto &problem = normalizedDescription.problem.value();
REQUIRE(domain->derivedPredicates.size() == 4);
REQUIRE(problem->derivedPredicates.size() == 2);
CHECK(domain->derivedPredicates[0]->name == "derived-predicate-1");
CHECK(domain->derivedPredicates[1]->name == "derived-predicate-2");
CHECK(domain->derivedPredicates[2]->name == "derived-predicate-3");
CHECK(domain->derivedPredicates[3]->name == "derived-predicate-4");
CHECK(problem->derivedPredicates[0]->name == "derived-predicate-5");
CHECK(problem->derivedPredicates[1]->name == "derived-predicate-6");
}
SECTION("derived predicates introduced by domain only")
{
const auto domainFile = fs::path("data") / "normalization" / "normalization-6-2.pddl";
context.tokenizer.read(domainFile);
auto description = pddl::parseDescription(context);
const auto normalizedDescription = pddl::normalize(std::move(description));
const auto &domain = normalizedDescription.domain;
REQUIRE(!normalizedDescription.problem);
REQUIRE(domain->derivedPredicates.size() == 4);
CHECK(domain->derivedPredicates[0]->name == "derived-predicate-1");
CHECK(domain->derivedPredicates[1]->name == "derived-predicate-2");
CHECK(domain->derivedPredicates[2]->name == "derived-predicate-3");
CHECK(domain->derivedPredicates[3]->name == "derived-predicate-4");
}
SECTION("derived predicates introduced by both domain and problem")
{
const auto domainFile = fs::path("data") / "normalization" / "normalization-6-3.pddl";
context.tokenizer.read(domainFile);
auto description = pddl::parseDescription(context);
const auto normalizedDescription = pddl::normalize(std::move(description));
const auto &domain = normalizedDescription.domain;
const auto &problem = normalizedDescription.problem.value();
REQUIRE(domain->derivedPredicates.empty());
REQUIRE(problem->derivedPredicates.size() == 2);
CHECK(problem->derivedPredicates[0]->name == "derived-predicate-1");
CHECK(problem->derivedPredicates[1]->name == "derived-predicate-2");
}
}

View File

@ -0,0 +1,47 @@
; tests derived predicates are correclty numbered
; variation 1: derived predicates both in domain and problem
(define (domain test-normalization)
(:predicates
(test-predicate-0))
; introduces derived predicates 1 and 2
(:action test-action-1
:parameters
(?x)
:precondition
(or
(test-predicate-0)
(and
(test-predicate-0)
(test-predicate-0)))
:effect
(test-predicate-0))
; introduces derived predicates 3 and 4
(:action test-action-1
:parameters
(?x)
:precondition
(or
(test-predicate-0)
(and
(test-predicate-0)
(test-predicate-0)))
:effect
(test-predicate-0)))
(define (problem test-normalization)
(:domain test-normalization)
(:objects a b c)
(:init
(test-predicate-0))
; introduces derived predicates 5 and 6
(:goal
(or
(test-predicate-0)
(and
(test-predicate-0)
(test-predicate-0)))))

View File

@ -0,0 +1,32 @@
; tests derived predicates are correclty numbered
; variation 2: derived predicates in domain only
(define (domain test-normalization)
(:predicates
(test-predicate-0))
; introduces derived predicates 1 and 2
(:action test-action-1
:parameters
(?x)
:precondition
(or
(test-predicate-0)
(and
(test-predicate-0)
(test-predicate-0)))
:effect
(test-predicate-0))
; introduces derived predicates 3 and 4
(:action test-action-1
:parameters
(?x)
:precondition
(or
(test-predicate-0)
(and
(test-predicate-0)
(test-predicate-0)))
:effect
(test-predicate-0))
)

View File

@ -0,0 +1,29 @@
; tests derived predicates are correclty numbered
; variation 3: derived predicates in problem only
(define (domain test-normalization)
(:predicates
(test-predicate-0))
(:action test-action-1
:parameters
(?x)
:precondition
(test-predicate-0)
:effect
(test-predicate-0)))
(define (problem test-normalization)
(:domain test-normalization)
(:objects a b c)
(:init
(test-predicate-0))
; introduces derived predicates 1 and 2
(:goal
(or
(test-predicate-0)
(and
(test-predicate-0)
(test-predicate-0)))))