Skip to content

Commit

Permalink
Minimal test added... more would be good but would need a lot of mock…
Browse files Browse the repository at this point in the history
…s... or maybe TrivialForcingProvider could be used?
  • Loading branch information
Matt Williamson authored and mattw-nws committed Aug 26, 2022
1 parent 55c676b commit 13dcd18
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/realizations/catchment/Catchment_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ namespace realization {
: Formulation(id), HY_CatchmentArea(forcing, output_stream) {
// Assume the catchment ID is equal to or embedded in the formulation `id`
size_t idx = id.find(".");
cat_id = ( idx == std::string::npos ? id : id.substr(0, idx) );
set_catchment_id( idx == std::string::npos ? id : id.substr(0, idx) );
};

Catchment_Formulation(std::string id) : Formulation(id){
// Assume the catchment ID is equal to or embedded in the formulation `id`
size_t idx = id.find(".");
cat_id = ( idx == std::string::npos ? id : id.substr(0, idx) );
set_catchment_id( idx == std::string::npos ? id : id.substr(0, idx) );
};

/**
Expand Down Expand Up @@ -95,11 +95,11 @@ namespace realization {

protected:
std::string get_catchment_id() override {
return id;
return this->cat_id;
}

void set_catchment_id(std::string cat_id) override {
id = cat_id;
this->cat_id = cat_id;
}

//TODO: VERY BAD JUJU...the following two members are an ugly hack to avoid having to gut the legacy C/C++ realizations for now.
Expand Down
23 changes: 23 additions & 0 deletions test/realizations/catchments/Bmi_Multi_Formulation_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ class Bmi_Multi_Formulation_Test : public ::testing::Test {
return nested->get_var_value_as_double(var_name);
}

static std::string get_friend_catchment_id(Bmi_Multi_Formulation& formulation){
return formulation.get_catchment_id();
}

template <class N>
static std::string get_friend_nested_catchment_id(const Bmi_Multi_Formulation& formulation, const int mod_index) {
std::shared_ptr<N> nested = std::static_pointer_cast<N>(formulation.modules[mod_index]);
return nested->get_catchment_id();
}

/*
static std::vector<nested_module_ptr> get_friend_nested_formulations(Bmi_Multi_Formulation& formulation) {
return formulation.get_bmi_model();
Expand Down Expand Up @@ -787,6 +797,19 @@ TEST_F(Bmi_Multi_Formulation_Test, GetOutputLineForTimestep_3_a) {
ASSERT_EQ(output, "0.000001112,199280.000000000,199240.000000000,199280.000000000,0.000000000,0.000001001");
}

/**
* Test if Catchment Ids of submodules correctly trim any suffix
*/
TEST_F(Bmi_Multi_Formulation_Test, GetIdAndCatchmentId) {
int ex_index = 3;

Bmi_Multi_Formulation formulation(catchment_ids[ex_index], std::make_unique<CsvPerFeatureForcingProvider>(*forcing_params_examples[ex_index]), utils::StreamHandler());
formulation.create_formulation(config_prop_ptree[ex_index]);
ASSERT_EQ(formulation.get_id(), "cat-27");
ASSERT_EQ(get_friend_catchment_id(formulation), "cat-27");
ASSERT_EQ(get_friend_nested_catchment_id<Bmi_Fortran_Formulation>(formulation, 0), "cat-27");
//ASSERT_EQ(formulation.get_catchment_id(), "id");
}
#endif // NGEN_BMI_C_LIB_ACTIVE || NGEN_BMI_FORTRAN_ACTIVE || ACTIVATE_PYTHON

#endif // NGEN_BMI_MULTI_FORMULATION_TEST_CPP

0 comments on commit 13dcd18

Please sign in to comment.