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);
|
|
|
|
ASSERT_EQ(domain.requirements()[0], plasp::pddl::Requirement::Type::STRIPS);
|
|
|
|
ASSERT_EQ(domain.requirements()[1], plasp::pddl::Requirement::Type::Typing);
|
2016-05-30 20:43:36 +02:00
|
|
|
|
|
|
|
ASSERT_EQ(domain.types().size(), 1u);
|
|
|
|
|
|
|
|
const auto blockType = domain.types().find("block");
|
|
|
|
ASSERT_NE(blockType, domain.types().cend());
|
|
|
|
|
|
|
|
ASSERT_EQ(blockType->second.name(), "block");
|
|
|
|
ASSERT_EQ(blockType->second.parentTypes().size(), 0u);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
ASSERT_EQ(domain.requirements()[0], plasp::pddl::Requirement::Type::Typing);
|
|
|
|
|
|
|
|
const auto area = domain.types().find("area");
|
|
|
|
ASSERT_NE(area, domain.types().cend());
|
|
|
|
const auto hoist = domain.types().find("hoist");
|
|
|
|
ASSERT_NE(hoist, domain.types().cend());
|
|
|
|
const auto object = domain.types().find("object");
|
|
|
|
ASSERT_NE(object, domain.types().cend());
|
|
|
|
const auto storearea = domain.types().find("storearea");
|
|
|
|
ASSERT_NE(storearea, domain.types().cend());
|
|
|
|
const auto surface= domain.types().find("surface");
|
|
|
|
ASSERT_NE(surface, domain.types().cend());
|
|
|
|
|
|
|
|
const auto &hoistParents = hoist->second.parentTypes();
|
|
|
|
ASSERT_EQ(hoistParents.size(), 1u);
|
|
|
|
ASSERT_TRUE(std::find(hoistParents.cbegin(), hoistParents.cend(), &object->second) != hoistParents.cend());
|
|
|
|
|
|
|
|
const auto &areaParents = area->second.parentTypes();
|
|
|
|
ASSERT_EQ(areaParents.size(), 2u);
|
|
|
|
ASSERT_TRUE(std::find(areaParents.cbegin(), areaParents.cend(), &object->second) != areaParents.cend());
|
|
|
|
ASSERT_TRUE(std::find(areaParents.cbegin(), areaParents.cend(), &surface->second) != areaParents.cend());
|
2016-05-30 15:44:13 +02:00
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
|
|
|
FAIL() << e.what();
|
|
|
|
}
|
|
|
|
}
|