2016-09-02 18:27:00 +02:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2016-09-02 18:32:13 +02:00
|
|
|
#include <plasp/pddl/expressions/Dummy.h>
|
2016-09-02 18:45:00 +02:00
|
|
|
#include <plasp/pddl/expressions/Imply.h>
|
2016-09-02 18:27:00 +02:00
|
|
|
#include <plasp/pddl/expressions/Not.h>
|
2016-09-02 18:45:00 +02:00
|
|
|
#include <plasp/pddl/expressions/Or.h>
|
2016-09-02 18:27:00 +02:00
|
|
|
|
|
|
|
using namespace plasp::pddl;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-09-02 18:45:00 +02:00
|
|
|
TEST(PDDLNormalizationTests, Implication)
|
|
|
|
{
|
2016-09-04 18:26:02 +02:00
|
|
|
auto i = expressions::ImplyPointer(new expressions::Imply);
|
|
|
|
auto d1 = expressions::DummyPointer(new expressions::Dummy);
|
2016-09-02 18:45:00 +02:00
|
|
|
const auto d1p = d1.get();
|
2016-09-04 18:26:02 +02:00
|
|
|
auto d2 = expressions::DummyPointer(new expressions::Dummy);
|
2016-09-02 18:45:00 +02:00
|
|
|
const auto d2p = d2.get();
|
|
|
|
|
2016-09-04 18:48:46 +02:00
|
|
|
i->setArgument(0, d1);
|
|
|
|
i->setArgument(1, d2);
|
2016-09-02 18:45:00 +02:00
|
|
|
|
2016-09-04 19:29:05 +02:00
|
|
|
auto normalized = i->normalized();
|
2016-09-02 18:45:00 +02:00
|
|
|
|
|
|
|
ASSERT_EQ(normalized->expressionType(), Expression::Type::Or);
|
|
|
|
|
|
|
|
const auto &o = dynamic_cast<expressions::Or &>(*normalized);
|
|
|
|
|
|
|
|
ASSERT_EQ(o.arguments()[0]->expressionType(), Expression::Type::Not);
|
|
|
|
|
|
|
|
const auto &n = dynamic_cast<const expressions::Not &>(*o.arguments()[0]);
|
|
|
|
|
|
|
|
ASSERT_EQ(n.argument(), d1p);
|
|
|
|
ASSERT_EQ(o.arguments()[1], d2p);
|
2016-09-02 19:25:25 +02:00
|
|
|
ASSERT_TRUE(d1p->isNormalized());
|
|
|
|
ASSERT_TRUE(d2p->isNormalized());
|
2016-09-02 18:45:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-09-02 18:27:00 +02:00
|
|
|
TEST(PDDLNormalizationTests, DoubleNegation)
|
|
|
|
{
|
2016-09-04 18:26:02 +02:00
|
|
|
auto n1 = expressions::NotPointer(new expressions::Not);
|
|
|
|
auto n2 = expressions::NotPointer(new expressions::Not);
|
|
|
|
auto d = expressions::DummyPointer(new expressions::Dummy);
|
2016-09-02 18:32:13 +02:00
|
|
|
const auto dp = d.get();
|
2016-09-02 18:27:00 +02:00
|
|
|
|
2016-09-02 18:32:13 +02:00
|
|
|
n2->setArgument(std::move(d));
|
2016-09-02 18:27:00 +02:00
|
|
|
n1->setArgument(std::move(n2));
|
|
|
|
|
2016-09-04 19:29:05 +02:00
|
|
|
auto normalized = n1->normalized();
|
2016-09-02 18:27:00 +02:00
|
|
|
|
2016-09-02 18:32:13 +02:00
|
|
|
ASSERT_EQ(normalized.get(), dp);
|
|
|
|
ASSERT_TRUE(dp->isNormalized());
|
2016-09-02 18:27:00 +02:00
|
|
|
}
|