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:
parent
39410ac98b
commit
5af0c26650
@ -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
Normal file
47
tests/data/normalization/normalization-6-1.pddl
Normal 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)))))
|
32
tests/data/normalization/normalization-6-2.pddl
Normal file
32
tests/data/normalization/normalization-6-2.pddl
Normal 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))
|
||||
)
|
29
tests/data/normalization/normalization-6-3.pddl
Normal file
29
tests/data/normalization/normalization-6-3.pddl
Normal 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)))))
|
Reference in New Issue
Block a user