Skip to content

Commit

Permalink
Use gmock for regex testing
Browse files Browse the repository at this point in the history
  • Loading branch information
hellkite500 authored and mattw-nws committed Mar 10, 2022
1 parent 93d7e81 commit a099619
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ project(test)

add_subdirectory(googletest)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
include_directories(${gmock_SOURCE_DIR}/include ${gmock_SOURCE_DIR})
include_directories(${PROJ_ROOT_INCLUDE_DIR})

if (NGEN_ACTIVATE_PYTHON)
Expand Down
12 changes: 5 additions & 7 deletions test/realizations/catchments/Bmi_C_Formulation_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
#include "Bmi_Module_Formulation.hpp"
#include "Bmi_C_Formulation.hpp"
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <iostream>
#include <vector>
#include <regex>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include "FileChecker.h"
#include "Formulation_Manager.hpp"
#include "Forcing.h"
#include <boost/date_time.hpp>

using ::testing::MatchesRegex;
using namespace realization;

class Bmi_C_Formulation_Test : public ::testing::Test {
Expand Down Expand Up @@ -306,8 +307,7 @@ TEST_F(Bmi_C_Formulation_Test, GetOutputLineForTimestep_0_a) {

formulation.get_response(0, 3600);
std::string output = formulation.get_output_line_for_timestep(0, ",");
std::regex expected ("(-?)0.000000,(-?)0.000000");
ASSERT_TRUE(std::regex_match(output, expected));
EXPECT_THAT(output, MatchesRegex("-?0.000000,-?0.000000"));
}

/** Simple test of output with modified variables. */
Expand All @@ -323,8 +323,7 @@ TEST_F(Bmi_C_Formulation_Test, GetOutputLineForTimestep_1_a) {
// OUTPUT_VAR_1 first.
formulation.get_response(0, 3600);
std::string output = formulation.get_output_line_for_timestep(0, ",");
std::regex expected ("(-?)0.000000,(-?)0.000000");
ASSERT_TRUE(std::regex_match(output, expected));
EXPECT_THAT(output, MatchesRegex("-?0.000000,-?0.000000"));
}

/** Simple test of output with modified variables, picking time step when there was non-zero rain rate. */
Expand All @@ -339,8 +338,7 @@ TEST_F(Bmi_C_Formulation_Test, GetOutputLineForTimestep_1_b) {
formulation.get_response(i++, 3600);
formulation.get_response(i, 3600);
std::string output = formulation.get_output_line_for_timestep(i, ",");
std::regex expected ("(-?)0.000000,0.000001");
ASSERT_TRUE(std::regex_match(output, expected));
EXPECT_THAT(output, MatchesRegex("-?0.000000,0.000001"));
}

TEST_F(Bmi_C_Formulation_Test, determine_model_time_offset_0_a) {
Expand Down

0 comments on commit a099619

Please sign in to comment.