UDQ: get from an unknown summary variable throws std::out_of_range

This commit is contained in:
Joakim Hove
2020-09-08 08:19:17 +02:00
parent aeb55ec72e
commit 4a9ec1403e
2 changed files with 8 additions and 20 deletions

View File

@@ -83,10 +83,7 @@ bool is_udq(const std::string& key) {
if (pair_ptr != this->values.end())
return pair_ptr->second;
if (this->summary_state.has(key))
return this->summary_state.get(key);
return std::nullopt;
return this->summary_state.get(key);
}
std::optional<double> UDQContext::get_well_var(const std::string& well, const std::string& var) const {
@@ -96,10 +93,7 @@ bool is_udq(const std::string& key) {
return std::nullopt;
}
if (this->summary_state.has_well_var(well, var))
return this->summary_state.get_well_var(well, var);
return std::nullopt;
return this->summary_state.get_well_var(well, var);
}
std::optional<double> UDQContext::get_group_var(const std::string& group, const std::string& var) const {
@@ -109,10 +103,7 @@ bool is_udq(const std::string& key) {
return std::nullopt;
}
if (this->summary_state.has_group_var(group, var))
return this->summary_state.get_group_var(group, var);
return std::nullopt;
return this->summary_state.get_group_var(group, var);
}
std::vector<std::string> UDQContext::wells() const {

View File

@@ -564,9 +564,7 @@ BOOST_AUTO_TEST_CASE(UDQ_CONTEXT) {
UDQState udq_state(udqp.undefinedValue());
UDQContext ctx(func_table, st, udq_state);
BOOST_CHECK_EQUAL(*ctx.get("JAN"), 1.0);
auto invalid = ctx.get("NO_SUCH_KEY");
BOOST_CHECK(!invalid.has_value());
BOOST_CHECK_THROW(ctx.get("NO_SUCH_KEY"), std::out_of_range);
for (std::string& key : std::vector<std::string>({"ELAPSED", "MSUMLINS", "MSUMNEWT", "NEWTON", "TCPU", "TIME", "TIMESTEP"}))
BOOST_CHECK_NO_THROW( ctx.get(key) );
@@ -2137,14 +2135,14 @@ DEFINE FU_VAR91 GOPR TEST /
BOOST_AUTO_TEST_CASE(UDQ_ASSIGN) {
BOOST_AUTO_TEST_CASE(UDQ_KEY_ERROR) {
std::string deck_string = R"(
-- udq #2
SCHEDULE
UDQ
ASSIGN FU_VAR1 5 /
DEFINE FU_VAR1 FU_VAR1 + 5 /
DEFINE FU_VAR1 FOPR * 5 /
/
)";
@@ -2154,6 +2152,5 @@ UDQ
UDQState udq_state(undefined_value);
SummaryState st(std::chrono::system_clock::now());
udq.eval(0, st, udq_state);
BOOST_CHECK_EQUAL(st.get("FU_VAR1"), 10);
BOOST_CHECK_THROW(udq.eval(0, st, udq_state), std::out_of_range);
}