diff --git a/opm/parser/eclipse/EclipseState/Schedule/Action/ActionAST.hpp b/opm/parser/eclipse/EclipseState/Schedule/Action/ActionAST.hpp index 3410ee1f1..7e3a2c9b8 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Action/ActionAST.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Action/ActionAST.hpp @@ -44,7 +44,12 @@ class AST{ public: AST() = default; explicit AST(const std::vector& tokens); + AST(const std::shared_ptr& cond); Result eval(const Context& context) const; + + std::shared_ptr getCondition() const; + + bool operator==(const AST& data) const; private: /* The use of a pointer here is to be able to create this class with only a diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionAST.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionAST.cpp index dbb2e0e40..c70bd6942 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionAST.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionAST.cpp @@ -38,6 +38,10 @@ AST::AST(const std::vector& tokens) { this->condition.reset( new Action::ASTNode(condition_node) ); } +AST::AST(const std::shared_ptr& cond) + : condition(cond) +{} + Action::Result AST::eval(const Action::Context& context) const { if (this->condition) @@ -45,5 +49,21 @@ Action::Result AST::eval(const Action::Context& context) const { else return Action::Result(false); } + + +std::shared_ptr AST::getCondition() const { + return condition; +} + + +bool AST::operator==(const AST& data) const { + if ((condition && !data.condition) || + (!condition && data.condition)) + return false; + + return !condition || (*condition == *data.condition); +} + + } } diff --git a/tests/parser/ACTIONX.cpp b/tests/parser/ACTIONX.cpp index ce4d31376..06555809e 100644 --- a/tests/parser/ACTIONX.cpp +++ b/tests/parser/ACTIONX.cpp @@ -232,13 +232,13 @@ TSTEP BOOST_AUTO_TEST_CASE(TestAction_AST_BASIC) { // Missing comparator - BOOST_REQUIRE_THROW( Action::AST( {"WWCT", "OPX", "0.75"} ), std::invalid_argument); + BOOST_REQUIRE_THROW( Action::AST( std::vector{"WWCT", "OPX", "0.75"} ), std::invalid_argument); // Left hand side must be function expression - BOOST_REQUIRE_THROW( Action::AST({"0.75", "<", "1.0"}), std::invalid_argument); + BOOST_REQUIRE_THROW( Action::AST(std::vector{"0.75", "<", "1.0"}), std::invalid_argument); //Extra data - BOOST_REQUIRE_THROW(Action::AST({"0.75", "<", "1.0", "EXTRA"}), std::invalid_argument); + BOOST_REQUIRE_THROW(Action::AST(std::vector{"0.75", "<", "1.0", "EXTRA"}), std::invalid_argument); Action::AST ast1({"WWCT", "OPX", ">", "0.75"}); Action::AST ast2({"WWCT", "OPX", "=", "WWCT", "OPX"}); @@ -296,7 +296,7 @@ BOOST_AUTO_TEST_CASE(TestAction_AST_OR_AND) { } BOOST_AUTO_TEST_CASE(DATE) { - Action::AST ast({"MNTH", ">=", "JUN"}); + Action::AST ast(std::vector{"MNTH", ">=", "JUN"}); SummaryState st(std::chrono::system_clock::now()); Action::Context context(st);