2016-05-30 15:44:13 +02:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
#include <plasp/pddl/Description.h>
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class PDDLParserTests : public ::testing::Test
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
PDDLParserTests()
|
2016-05-30 20:43:36 +02:00
|
|
|
: m_blocksworldDomainFile(readFile("data/blocksworld-domain.pddl")),
|
|
|
|
m_storageDomainFile(readFile("data/storage-domain.pddl"))
|
2016-05-30 15:44:13 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::stringstream readFile(const std::string &path)
|
|
|
|
{
|
|
|
|
std::ifstream fileStream(path, std::ios::in);
|
|
|
|
|
|
|
|
std::stringstream outputStream;
|
|
|
|
|
|
|
|
if (!fileStream.is_open())
|
|
|
|
throw std::runtime_error("Could not open file \"" + path + "\"");
|
|
|
|
|
|
|
|
outputStream << fileStream.rdbuf();
|
|
|
|
|
|
|
|
return outputStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::stringstream m_blocksworldDomainFile;
|
2016-05-30 20:43:36 +02:00
|
|
|
std::stringstream m_storageDomainFile;
|
2016-05-30 15:44:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-05-30 20:43:36 +02:00
|
|
|
TEST_F(PDDLParserTests, ParseBlocksWorldDomain)
|
2016-05-30 15:44:13 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const auto description = plasp::pddl::Description::fromStream(m_blocksworldDomainFile);
|
|
|
|
|
|
|
|
ASSERT_NO_THROW(description.domain());
|
|
|
|
|
|
|
|
const auto &domain = description.domain();
|
|
|
|
|
2016-05-30 20:43:36 +02:00
|
|
|
ASSERT_EQ(domain.name(), "BLOCKS");
|
|
|
|
|
2016-05-30 15:44:13 +02:00
|
|
|
ASSERT_EQ(domain.requirements().size(), 2u);
|
2016-05-31 14:11:21 +02:00
|
|
|
ASSERT_EQ(domain.requirements()[0].type(), plasp::pddl::Requirement::Type::STRIPS);
|
|
|
|
ASSERT_EQ(domain.requirements()[1].type(), plasp::pddl::Requirement::Type::Typing);
|
2016-05-30 20:43:36 +02:00
|
|
|
|
|
|
|
ASSERT_EQ(domain.types().size(), 1u);
|
|
|
|
|
2016-06-01 01:29:46 +02:00
|
|
|
const auto block = boost::get<plasp::pddl::TypePrimitive>(domain.types().find("block")->second);
|
2016-05-30 20:43:36 +02:00
|
|
|
|
2016-06-01 01:29:46 +02:00
|
|
|
ASSERT_EQ(block.name(), "block");
|
|
|
|
ASSERT_EQ(block.parentTypes().size(), 0u);
|
2016-05-31 16:43:25 +02:00
|
|
|
|
|
|
|
ASSERT_EQ(domain.predicates().size(), 5u);
|
|
|
|
|
|
|
|
const auto on = domain.predicates().find({"on", 2});
|
2016-05-30 20:43:36 +02:00
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
|
|
|
FAIL() << e.what();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
TEST_F(PDDLParserTests, ParseStorageDomain)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const auto description = plasp::pddl::Description::fromStream(m_storageDomainFile);
|
|
|
|
|
|
|
|
ASSERT_NO_THROW(description.domain());
|
|
|
|
|
|
|
|
const auto &domain = description.domain();
|
|
|
|
|
|
|
|
ASSERT_EQ(domain.name(), "Storage-Propositional");
|
|
|
|
|
|
|
|
ASSERT_EQ(domain.requirements().size(), 1u);
|
2016-05-31 14:11:21 +02:00
|
|
|
ASSERT_EQ(domain.requirements()[0].type(), plasp::pddl::Requirement::Type::Typing);
|
2016-05-30 20:43:36 +02:00
|
|
|
|
2016-06-01 01:29:46 +02:00
|
|
|
const auto area = boost::get<plasp::pddl::TypePrimitive>(domain.types().find("area")->second);
|
|
|
|
const auto hoist = boost::get<plasp::pddl::TypePrimitive>(domain.types().find("hoist")->second);
|
|
|
|
const auto object = boost::get<plasp::pddl::TypePrimitive>(domain.types().find("object")->second);
|
|
|
|
const auto storearea = boost::get<plasp::pddl::TypePrimitive>(domain.types().find("storearea")->second);
|
|
|
|
const auto surface = boost::get<plasp::pddl::TypePrimitive>(domain.types().find("surface")->second);
|
|
|
|
|
|
|
|
const auto &hoistParents = hoist.parentTypes();
|
2016-05-30 20:43:36 +02:00
|
|
|
ASSERT_EQ(hoistParents.size(), 1u);
|
2016-06-01 01:29:46 +02:00
|
|
|
ASSERT_TRUE(std::find(hoistParents.cbegin(), hoistParents.cend(), &object) != hoistParents.cend());
|
2016-05-30 20:43:36 +02:00
|
|
|
|
2016-06-01 01:29:46 +02:00
|
|
|
const auto &areaParents = area.parentTypes();
|
2016-05-30 20:43:36 +02:00
|
|
|
ASSERT_EQ(areaParents.size(), 2u);
|
2016-06-01 01:29:46 +02:00
|
|
|
ASSERT_TRUE(std::find(areaParents.cbegin(), areaParents.cend(), &object) != areaParents.cend());
|
|
|
|
ASSERT_TRUE(std::find(areaParents.cbegin(), areaParents.cend(), &surface) != areaParents.cend());
|
2016-05-30 15:44:13 +02:00
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
|
|
|
FAIL() << e.what();
|
|
|
|
}
|
|
|
|
}
|