From d23ec14e9d7845ef6892d9c8888e6456020ec63d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Wed, 8 Jun 2016 13:52:36 +0200 Subject: [PATCH] Started testing PDDL problem parsing for a Blocks World problem. --- include/plasp/pddl/Description.h | 1 + src/plasp/pddl/Description.cpp | 9 ++++++ tests/TestPDDLParser.cpp | 47 ++++++++++++++++++++++++----- tests/data/blocksworld-problem.pddl | 7 +++++ 4 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 tests/data/blocksworld-problem.pddl diff --git a/include/plasp/pddl/Description.h b/include/plasp/pddl/Description.h index d44ff59..989df12 100644 --- a/include/plasp/pddl/Description.h +++ b/include/plasp/pddl/Description.h @@ -27,6 +27,7 @@ class Description public: const Domain &domain() const; + const Problem &problem() const; private: Description(); diff --git a/src/plasp/pddl/Description.cpp b/src/plasp/pddl/Description.cpp index dc971f7..fd3f5fe 100644 --- a/src/plasp/pddl/Description.cpp +++ b/src/plasp/pddl/Description.cpp @@ -88,6 +88,15 @@ const Domain &Description::domain() const //////////////////////////////////////////////////////////////////////////////////////////////////// +const Problem &Description::problem() const +{ + BOOST_ASSERT(m_problem); + + return *m_problem; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + void Description::parseContent() { // First, determine the locations of domain and problem diff --git a/tests/TestPDDLParser.cpp b/tests/TestPDDLParser.cpp index 540f5c0..a59679c 100644 --- a/tests/TestPDDLParser.cpp +++ b/tests/TestPDDLParser.cpp @@ -13,12 +13,12 @@ #include #include +using namespace plasp::pddl; + //////////////////////////////////////////////////////////////////////////////////////////////////// TEST(PDDLParserTests, ParseBlocksWorldDomain) { - using namespace plasp::pddl; - const auto description = Description::fromFile("data/blocksworld-domain.pddl"); ASSERT_NO_THROW(description.domain()); @@ -96,10 +96,38 @@ TEST(PDDLParserTests, ParseBlocksWorldDomain) //////////////////////////////////////////////////////////////////////////////////////////////////// +TEST(PDDLParserTests, ParseBlocksWorldProblem) +{ + const auto description = Description::fromFiles({"data/blocksworld-domain.pddl", "data/blocksworld-problem.pddl"}); + + ASSERT_NO_THROW(description.problem()); + + const auto &problem = description.problem(); + + // Name + ASSERT_EQ(problem.name(), "blocks-4-0"); + ASSERT_EQ(problem.domain().name(), "blocks"); + + // Requirements + // TODO: compute domain vs. problem requirements correctly and check them + + // Objects + ASSERT_EQ(problem.objects().size(), 4u); + + ASSERT_EQ(problem.objects()[0]->name(), "d"); + ASSERT_NE(problem.objects()[0]->type(), nullptr); + ASSERT_EQ(problem.objects()[0]->type()->name(), "block"); + ASSERT_EQ(problem.objects()[3]->name(), "c"); + ASSERT_NE(problem.objects()[3]->type(), nullptr); + ASSERT_EQ(problem.objects()[3]->type()->name(), "block"); + + // TODO: check initial state and goal +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + TEST(PDDLParserTests, ParseStorageDomain) { - using namespace plasp::pddl; - const auto description = plasp::pddl::Description::fromFile("data/storage-domain.pddl"); ASSERT_NO_THROW(description.domain()); @@ -191,8 +219,6 @@ TEST(PDDLParserTests, ParseStorageDomain) TEST(PDDLParserTests, ParseConstants) { - using namespace plasp::pddl; - const auto description = Description::fromFile("data/woodworking-domain.pddl"); ASSERT_NO_THROW(description.domain()); @@ -222,7 +248,12 @@ TEST(PDDLParserTests, ParseConstants) TEST(PDDLParserTests, ParseWithWhiteSpace) { - using namespace plasp::pddl; - ASSERT_NO_THROW(Description::fromFile("data/white-space-test.pddl")); } + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +TEST(PDDLParserTests, ParseWithoutDomain) +{ + ASSERT_THROW(Description::fromFile("data/blocksworld-problem.pddl"), plasp::pddl::ConsistencyException); +} diff --git a/tests/data/blocksworld-problem.pddl b/tests/data/blocksworld-problem.pddl new file mode 100644 index 0000000..b50db9d --- /dev/null +++ b/tests/data/blocksworld-problem.pddl @@ -0,0 +1,7 @@ +(define (problem BLOCKS-4-0) +(:domain BLOCKS) +(:objects D B A C - block) +(:INIT (CLEAR C) (CLEAR A) (CLEAR B) (CLEAR D) (ONTABLE C) (ONTABLE A) + (ONTABLE B) (ONTABLE D) (HANDEMPTY)) +(:goal (AND (ON D C) (ON C B) (ON B A))) +)