Refactored PDDL tests.
This commit is contained in:
parent
1c8958ad9d
commit
ad23c89266
@ -22,6 +22,7 @@ class Description
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Description fromStream(std::istream &istream);
|
static Description fromStream(std::istream &istream);
|
||||||
|
static Description fromFile(const std::string &path);
|
||||||
static Description fromFiles(const std::vector<std::string> &paths);
|
static Description fromFiles(const std::vector<std::string> &paths);
|
||||||
|
|
||||||
public:
|
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)
|
Description Description::fromFiles(const std::vector<std::string> &paths)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(!paths.empty());
|
BOOST_ASSERT(!paths.empty());
|
||||||
|
@ -15,46 +15,11 @@
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class PDDLParserTests : public ::testing::Test
|
TEST(PDDLParserTests, ParseBlocksWorldDomain)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
using namespace plasp::pddl;
|
using namespace plasp::pddl;
|
||||||
|
|
||||||
try
|
const auto description = Description::fromFile("data/blocksworld-domain.pddl");
|
||||||
{
|
|
||||||
const auto description = Description::fromStream(m_blocksworldDomainFile);
|
|
||||||
|
|
||||||
ASSERT_NO_THROW(description.domain());
|
ASSERT_NO_THROW(description.domain());
|
||||||
|
|
||||||
@ -128,21 +93,14 @@ TEST_F(PDDLParserTests, ParseBlocksWorldDomain)
|
|||||||
ASSERT_EQ(pickUpEff000.name(), "x");
|
ASSERT_EQ(pickUpEff000.name(), "x");
|
||||||
ASSERT_EQ(pickUpEff000.type(), &block);
|
ASSERT_EQ(pickUpEff000.type(), &block);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
|
||||||
{
|
|
||||||
FAIL() << e.what();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TEST_F(PDDLParserTests, ParseStorageDomain)
|
TEST(PDDLParserTests, ParseStorageDomain)
|
||||||
{
|
{
|
||||||
using namespace plasp::pddl;
|
using namespace plasp::pddl;
|
||||||
|
|
||||||
try
|
const auto description = plasp::pddl::Description::fromFile("data/storage-domain.pddl");
|
||||||
{
|
|
||||||
const auto description = plasp::pddl::Description::fromStream(m_storageDomainFile);
|
|
||||||
|
|
||||||
ASSERT_NO_THROW(description.domain());
|
ASSERT_NO_THROW(description.domain());
|
||||||
|
|
||||||
@ -228,21 +186,14 @@ TEST_F(PDDLParserTests, ParseStorageDomain)
|
|||||||
ASSERT_EQ(dropEff200.name(), "a1");
|
ASSERT_EQ(dropEff200.name(), "a1");
|
||||||
ASSERT_EQ(dropEff200.type(), &storearea);
|
ASSERT_EQ(dropEff200.type(), &storearea);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
|
||||||
{
|
|
||||||
FAIL() << e.what();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TEST_F(PDDLParserTests, ParseConstants)
|
TEST(PDDLParserTests, ParseConstants)
|
||||||
{
|
{
|
||||||
using namespace plasp::pddl;
|
using namespace plasp::pddl;
|
||||||
|
|
||||||
try
|
const auto description = Description::fromFile("data/woodworking-domain.pddl");
|
||||||
{
|
|
||||||
const auto description = Description::fromStream(m_woodworkingDomainFile);
|
|
||||||
|
|
||||||
ASSERT_NO_THROW(description.domain());
|
ASSERT_NO_THROW(description.domain());
|
||||||
|
|
||||||
@ -266,24 +217,12 @@ TEST_F(PDDLParserTests, ParseConstants)
|
|||||||
|
|
||||||
// TODO: add test with constants in predicates
|
// 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;
|
using namespace plasp::pddl;
|
||||||
|
|
||||||
try
|
ASSERT_NO_THROW(Description::fromFile("data/white-space-test.pddl"));
|
||||||
{
|
|
||||||
ASSERT_NO_THROW(Description::fromStream(m_whiteSpaceTestFile));
|
|
||||||
}
|
|
||||||
catch (const std::exception &e)
|
|
||||||
{
|
|
||||||
FAIL() << e.what();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user