patrick
/
plasp
Archived
1
0
Fork 0

Parsing <none of those> values in SAS files.

This commit is contained in:
Patrick Lühne 2016-05-23 01:27:28 +02:00
parent 401c4069bd
commit d118788142
4 changed files with 34331 additions and 6 deletions

View File

@ -34,6 +34,7 @@ struct Value
};
static const Value Any;
static const Value None;
static Value fromSAS(std::istream &istream);
static const Value &referenceFromSAS(std::istream &istream, const Variable &variable);
@ -49,7 +50,7 @@ struct Value
const std::string &name() const;
private:
static const Value any();
static const Value reserved(const std::string &name);
private:
Value();
@ -61,6 +62,10 @@ struct Value
////////////////////////////////////////////////////////////////////////////////////////////////////
bool operator ==(const Value &value1, const Value &value2);
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}

View File

@ -16,18 +16,19 @@ namespace sas
//
////////////////////////////////////////////////////////////////////////////////////////////////////
const Value Value::any()
const Value Value::reserved(const std::string &name)
{
Value any;
any.m_name = "(any)";
any.m_name = name;
return any;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
const Value Value::Any = Value::any();
const Value Value::Any = Value::reserved("(any)");
const Value Value::None = Value::reserved("(none)");
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -54,10 +55,19 @@ Value Value::negated() const
Value Value::fromSAS(std::istream &istream)
{
Value value;
const auto sasSign = utils::parse<std::string>(istream);
if (sasSign == "<none")
{
utils::parseExpected<std::string>(istream, "of");
utils::parseExpected<std::string>(istream, "those>");
// TODO: do not return a copy of Value::None
return Value::None;
}
Value value;
if (sasSign == "Atom")
value.m_sign = Value::Sign::Positive;
else if (sasSign == "NegatedAtom")
@ -148,5 +158,18 @@ void Value::printAsSAS(std::ostream &ostream) const
////////////////////////////////////////////////////////////////////////////////////////////////////
bool operator ==(const Value &value1, const Value &value2)
{
if (value1.sign() != value2.sign())
return false;
if (value1.name() != value2.name())
return false;
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}

View File

@ -14,6 +14,7 @@ class SASParserTests : public ::testing::Test
protected:
SASParserTests()
: m_blocksworldTestFile(readFile("data/blocksworld.sas")),
m_freecellTestFile(readFile("data/freecell.sas")),
m_philosophersTestFile(readFile("data/philosophers.sas"))
{
}
@ -33,6 +34,7 @@ class SASParserTests : public ::testing::Test
}
std::stringstream m_blocksworldTestFile;
std::stringstream m_freecellTestFile;
std::stringstream m_philosophersTestFile;
};
@ -128,6 +130,24 @@ TEST_F(SASParserTests, RemoveTrailingParentheses)
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_F(SASParserTests, ParseNoneValue)
{
try
{
const auto description = plasp::sas::Description::fromStream(m_freecellTestFile);
// TODO: compare by identity, not value
ASSERT_EQ(description.variables()[0].values()[3], plasp::sas::Value::None);
ASSERT_EQ(description.variables()[5].values()[6], plasp::sas::Value::None);
}
catch (const std::exception &e)
{
FAIL () << e.what();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);

34277
tests/data/freecell.sas Normal file

File diff suppressed because it is too large Load Diff