Browse Source

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.
master
Patrick Lühne 4 years ago
parent
commit
5af0c26650
No known key found for this signature in database GPG Key ID: 5F3611E97A70ABF
  1. 64
      lib/pddl/tests/TestNormalization.cpp
  2. 47
      tests/data/normalization/normalization-6-1.pddl
  3. 32
      tests/data/normalization/normalization-6-2.pddl
  4. 29
      tests/data/normalization/normalization-6-3.pddl

64
lib/pddl/tests/TestNormalization.cpp

@ -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");
}
}

47
tests/data/normalization/normalization-6-1.pddl

@ -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)))))

32
tests/data/normalization/normalization-6-2.pddl

@ -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))
)

29
tests/data/normalization/normalization-6-3.pddl

@ -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)))))
Loading…
Cancel
Save