From 5af0c266507661008181c73a7470c51b4acbd47f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Thu, 16 Nov 2017 17:30:53 +0100 Subject: [PATCH] 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. --- lib/pddl/tests/TestNormalization.cpp | 64 +++++++++++++++++++ .../data/normalization/normalization-6-1.pddl | 47 ++++++++++++++ .../data/normalization/normalization-6-2.pddl | 32 ++++++++++ .../data/normalization/normalization-6-3.pddl | 29 +++++++++ 4 files changed, 172 insertions(+) create mode 100644 tests/data/normalization/normalization-6-1.pddl create mode 100644 tests/data/normalization/normalization-6-2.pddl create mode 100644 tests/data/normalization/normalization-6-3.pddl diff --git a/lib/pddl/tests/TestNormalization.cpp b/lib/pddl/tests/TestNormalization.cpp index 457d433..0bd989f 100644 --- a/lib/pddl/tests/TestNormalization.cpp +++ b/lib/pddl/tests/TestNormalization.cpp @@ -429,3 +429,67 @@ TEST_CASE("[normalization] Nested expressions are correctly flattened via derive CHECK(a31212->arguments[1].get()->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"); + } +} diff --git a/tests/data/normalization/normalization-6-1.pddl b/tests/data/normalization/normalization-6-1.pddl new file mode 100644 index 0000000..85a9466 --- /dev/null +++ b/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))))) diff --git a/tests/data/normalization/normalization-6-2.pddl b/tests/data/normalization/normalization-6-2.pddl new file mode 100644 index 0000000..edb5162 --- /dev/null +++ b/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)) +) diff --git a/tests/data/normalization/normalization-6-3.pddl b/tests/data/normalization/normalization-6-3.pddl new file mode 100644 index 0000000..234b100 --- /dev/null +++ b/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)))))