Refactored PDDL tests.

This commit is contained in:
Patrick Lühne 2016-06-08 13:41:17 +02:00
parent 1c8958ad9d
commit ad23c89266
3 changed files with 161 additions and 207 deletions

View File

@ -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:

View File

@ -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());

View File

@ -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());
@ -128,21 +93,14 @@ TEST_F(PDDLParserTests, ParseBlocksWorldDomain)
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());
@ -228,21 +186,14 @@ TEST_F(PDDLParserTests, ParseStorageDomain)
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());
@ -266,24 +217,12 @@ TEST_F(PDDLParserTests, ParseConstants)
// 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"));
}