Refactored PDDL tests.
This commit is contained in:
parent
1c8958ad9d
commit
ad23c89266
@ -22,6 +22,7 @@ class Description
|
||||
{
|
||||
public:
|
||||
static Description fromStream(std::istream &istream);
|
||||
static Description fromFile(const std::string &path);
|
||||
static Description fromFiles(const std::vector<std::string> &paths);
|
||||
|
||||
public:
|
||||
|
@ -45,6 +45,20 @@ Description Description::fromStream(std::istream &istream)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Description Description::fromFile(const std::string &path)
|
||||
{
|
||||
Description description;
|
||||
|
||||
description.m_parser.readFile(path);
|
||||
|
||||
description.parseContent();
|
||||
description.checkConsistency();
|
||||
|
||||
return description;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Description Description::fromFiles(const std::vector<std::string> &paths)
|
||||
{
|
||||
BOOST_ASSERT(!paths.empty());
|
||||
|
@ -15,46 +15,11 @@
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PDDLParserTests : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
PDDLParserTests()
|
||||
: m_blocksworldDomainFile(readFile("data/blocksworld-domain.pddl")),
|
||||
m_storageDomainFile(readFile("data/storage-domain.pddl")),
|
||||
m_whiteSpaceTestFile(readFile("data/white-space-test.pddl")),
|
||||
m_woodworkingDomainFile(readFile("data/woodworking-domain.pddl"))
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
std::stringstream m_storageDomainFile;
|
||||
std::stringstream m_whiteSpaceTestFile;
|
||||
std::stringstream m_woodworkingDomainFile;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST_F(PDDLParserTests, ParseBlocksWorldDomain)
|
||||
TEST(PDDLParserTests, ParseBlocksWorldDomain)
|
||||
{
|
||||
using namespace plasp::pddl;
|
||||
|
||||
try
|
||||
{
|
||||
const auto description = Description::fromStream(m_blocksworldDomainFile);
|
||||
const auto description = Description::fromFile("data/blocksworld-domain.pddl");
|
||||
|
||||
ASSERT_NO_THROW(description.domain());
|
||||
|
||||
@ -127,22 +92,15 @@ TEST_F(PDDLParserTests, ParseBlocksWorldDomain)
|
||||
const auto &pickUpEff000 = *dynamic_cast<const expressions::Reference<expressions::Variable> &>(*pickUpEff00.arguments()[0]).value();
|
||||
ASSERT_EQ(pickUpEff000.name(), "x");
|
||||
ASSERT_EQ(pickUpEff000.type(), &block);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
FAIL() << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST_F(PDDLParserTests, ParseStorageDomain)
|
||||
TEST(PDDLParserTests, ParseStorageDomain)
|
||||
{
|
||||
using namespace plasp::pddl;
|
||||
|
||||
try
|
||||
{
|
||||
const auto description = plasp::pddl::Description::fromStream(m_storageDomainFile);
|
||||
const auto description = plasp::pddl::Description::fromFile("data/storage-domain.pddl");
|
||||
|
||||
ASSERT_NO_THROW(description.domain());
|
||||
|
||||
@ -227,22 +185,15 @@ TEST_F(PDDLParserTests, ParseStorageDomain)
|
||||
const auto &dropEff200 = *dynamic_cast<const expressions::Reference<expressions::Variable> &>(*dropEff20.arguments()[0]).value();
|
||||
ASSERT_EQ(dropEff200.name(), "a1");
|
||||
ASSERT_EQ(dropEff200.type(), &storearea);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
FAIL() << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST_F(PDDLParserTests, ParseConstants)
|
||||
TEST(PDDLParserTests, ParseConstants)
|
||||
{
|
||||
using namespace plasp::pddl;
|
||||
|
||||
try
|
||||
{
|
||||
const auto description = Description::fromStream(m_woodworkingDomainFile);
|
||||
const auto description = Description::fromFile("data/woodworking-domain.pddl");
|
||||
|
||||
ASSERT_NO_THROW(description.domain());
|
||||
|
||||
@ -265,25 +216,13 @@ TEST_F(PDDLParserTests, ParseConstants)
|
||||
ASSERT_EQ(domain.constants()[7]->type(), &acolour);
|
||||
|
||||
// TODO: add test with constants in predicates
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
FAIL() << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST_F(PDDLParserTests, ParseWithWhiteSpace)
|
||||
TEST(PDDLParserTests, ParseWithWhiteSpace)
|
||||
{
|
||||
using namespace plasp::pddl;
|
||||
|
||||
try
|
||||
{
|
||||
ASSERT_NO_THROW(Description::fromStream(m_whiteSpaceTestFile));
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
FAIL() << e.what();
|
||||
}
|
||||
ASSERT_NO_THROW(Description::fromFile("data/white-space-test.pddl"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user