-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#10916 - Broken format strings in a few places like CurveManager #10917
Conversation
…or with format, '{} [{:.R2}] > {} [{.R2}]', passed 4 args"
TEST_F(EnergyPlusFixture, QuadraticCurve_CheckCurveMinMaxValues) | ||
{ | ||
std::string const idf_objects = delimited_string({ | ||
"Curve:Quadratic,", | ||
" DummyEIRfPLR, !- Name", | ||
" 1, !- Coefficient1 Constant", | ||
" 1, !- Coefficient2 x", | ||
" 0, !- Coefficient3 x**2", | ||
" 0.8, !- Minimum Value of x {BasedOnField A2}", | ||
" 0.5, !- Maximum Value of x {BasedOnField A2}", | ||
" , !- Minimum Curve Output {BasedOnField A3}", | ||
" , !- Maximum Curve Output {BasedOnField A3}", | ||
" , !- Input Unit Type for X", | ||
" ; !- Output Unit Type", | ||
}); | ||
|
||
EXPECT_TRUE(process_idf(idf_objects)); | ||
EXPECT_EQ(0, state->dataCurveManager->NumCurves); | ||
ASSERT_THROW(Curve::GetCurveInput(*state), std::runtime_error); | ||
state->dataCurveManager->GetCurvesInputFlag = false; | ||
ASSERT_EQ(1, state->dataCurveManager->NumCurves); | ||
|
||
auto const expected_error = delimited_string({ | ||
" ** Severe ** GetCurveInput: For Curve:Quadratic: ", | ||
" ** ~~~ ** Minimum Value of x [0.80] > Maximum Value of x [0.50]", | ||
" ** Fatal ** GetCurveInput: Errors found in getting Curve Objects. Preceding condition(s) cause termination.", | ||
}); | ||
EXPECT_TRUE(compare_err_stream_substring(expected_error)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple test, showing how it's going to work.
struct CurveTestParam | ||
{ | ||
std::string object_name; | ||
std::string tested_dim; | ||
std::string idf_objects; | ||
std::string expected_error; | ||
|
||
// This is what I want to override, so why I'm using a struct and not a std::tuple<std::string, std::string, std::string, std::string> | ||
friend std::ostream &operator<<(std::ostream &os, const CurveTestParam &p) | ||
{ | ||
return os << p.object_name << "_" << p.tested_dim; | ||
} | ||
}; | ||
|
||
class CurveManagerValidationFixture : public EnergyPlusFixture, public ::testing::WithParamInterface<CurveTestParam> | ||
{ | ||
public: | ||
static std::string delimited_string(std::vector<std::string> const &strings, std::string const &delimiter = "\n") | ||
{ | ||
return EnergyPlusFixture::delimited_string(strings, delimiter); | ||
} | ||
}; | ||
|
||
TEST_P(CurveManagerValidationFixture, CurveMinMaxValues) | ||
{ | ||
const auto &[object_name, tested_dim, idf_objects, expected_error] = GetParam(); | ||
EXPECT_TRUE(process_idf(idf_objects)); | ||
EXPECT_EQ(0, state->dataCurveManager->NumCurves); | ||
try { | ||
Curve::GetCurveInput(*state); | ||
} catch (const EnergyPlus::FatalError &err) { | ||
std::string w = err.what(); | ||
EXPECT_TRUE(w.find("Error with format") == std::string::npos) << w; | ||
// Otherwise, this is expected | ||
} catch (std::runtime_error const &err) { | ||
FAIL() << err.what(); | ||
} catch (...) { | ||
FAIL() << "Got another exception!"; | ||
} | ||
state->dataCurveManager->GetCurvesInputFlag = false; | ||
ASSERT_EQ(1, state->dataCurveManager->NumCurves); | ||
EXPECT_TRUE(compare_err_stream_substring(expected_error)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parametrized test
" Dimensionless, !- Input Unit Type for x", | ||
" Dimensionless, !- Input Unit Type for y", | ||
" Dimensionless; !- Input Unit Type for z", | ||
}), | ||
"Minimum Value of w [0.80] > Maximum Value of w [0.50]"}, | ||
CurveTestParam{"Curve:QuintLinear", | ||
"x", | ||
CurveManagerValidationFixture::delimited_string({ | ||
"Curve:QuintLinear,", | ||
" QuintLinear, !- Name", | ||
" 1, !- Coefficient1 Constant", | ||
" 1, !- Coefficient2 v", | ||
" 1, !- Coefficient3 w", | ||
" 1, !- Coefficient4 x", | ||
" 1, !- Coefficient5 y", | ||
" 1, !- Coefficient6 z", | ||
" 0, !- Minimum Value of v {BasedOnField A2}", | ||
" 1, !- Maximum Value of v {BasedOnField A2}", | ||
" 0, !- Minimum Value of w {BasedOnField A2}", | ||
" 1, !- Maximum Value of w {BasedOnField A2}", | ||
" 0.8, !- Minimum Value of x {BasedOnField A3}", | ||
" 0.5, !- Maximum Value of x {BasedOnField A3}", | ||
" 0, !- Minimum Value of y {BasedOnField A4}", | ||
" 1, !- Maximum Value of y {BasedOnField A4}", | ||
" 0, !- Minimum Value of z {BasedOnField A5}", | ||
" 1, !- Maximum Value of z {BasedOnField A5}", | ||
" , !- Minimum Curve Output {BasedOnField A4}", | ||
" , !- Maximum Curve Output {BasedOnField A4}", | ||
" Dimensionless, !- Input Unit Type for v", | ||
" Dimensionless, !- Input Unit Type for w", | ||
" Dimensionless, !- Input Unit Type for x", | ||
" Dimensionless, !- Input Unit Type for y", | ||
" Dimensionless; !- Input Unit Type for z", | ||
}), | ||
"Minimum Value of x [0.80] > Maximum Value of x [0.50]"}, | ||
CurveTestParam{"Curve:QuintLinear", | ||
"y", | ||
CurveManagerValidationFixture::delimited_string({ | ||
"Curve:QuintLinear,", | ||
" QuintLinear, !- Name", | ||
" 1, !- Coefficient1 Constant", | ||
" 1, !- Coefficient2 v", | ||
" 1, !- Coefficient3 w", | ||
" 1, !- Coefficient4 x", | ||
" 1, !- Coefficient5 y", | ||
" 1, !- Coefficient6 z", | ||
" 0, !- Minimum Value of v {BasedOnField A2}", | ||
" 1, !- Maximum Value of v {BasedOnField A2}", | ||
" 0, !- Minimum Value of w {BasedOnField A2}", | ||
" 1, !- Maximum Value of w {BasedOnField A2}", | ||
" 0, !- Minimum Value of x {BasedOnField A3}", | ||
" 1, !- Maximum Value of x {BasedOnField A3}", | ||
" 0.8, !- Minimum Value of y {BasedOnField A4}", | ||
" 0.5, !- Maximum Value of y {BasedOnField A4}", | ||
" 0, !- Minimum Value of z {BasedOnField A5}", | ||
" 1, !- Maximum Value of z {BasedOnField A5}", | ||
" , !- Minimum Curve Output {BasedOnField A4}", | ||
" , !- Maximum Curve Output {BasedOnField A4}", | ||
" Dimensionless, !- Input Unit Type for v", | ||
" Dimensionless, !- Input Unit Type for w", | ||
" Dimensionless, !- Input Unit Type for x", | ||
" Dimensionless, !- Input Unit Type for y", | ||
" Dimensionless; !- Input Unit Type for z", | ||
}), | ||
"Minimum Value of y [0.80] > Maximum Value of y [0.50]"}, | ||
CurveTestParam{"Curve:QuintLinear", | ||
"z", | ||
CurveManagerValidationFixture::delimited_string({ | ||
"Curve:QuintLinear,", | ||
" QuintLinear, !- Name", | ||
" 1, !- Coefficient1 Constant", | ||
" 1, !- Coefficient2 v", | ||
" 1, !- Coefficient3 w", | ||
" 1, !- Coefficient4 x", | ||
" 1, !- Coefficient5 y", | ||
" 1, !- Coefficient6 z", | ||
" 0, !- Minimum Value of v {BasedOnField A2}", | ||
" 1, !- Maximum Value of v {BasedOnField A2}", | ||
" 0, !- Minimum Value of w {BasedOnField A2}", | ||
" 1, !- Maximum Value of w {BasedOnField A2}", | ||
" 0, !- Minimum Value of x {BasedOnField A3}", | ||
" 1, !- Maximum Value of x {BasedOnField A3}", | ||
" 0, !- Minimum Value of y {BasedOnField A4}", | ||
" 1, !- Maximum Value of y {BasedOnField A4}", | ||
" 0.8, !- Minimum Value of z {BasedOnField A5}", | ||
" 0.5, !- Maximum Value of z {BasedOnField A5}", | ||
" , !- Minimum Curve Output {BasedOnField A4}", | ||
" , !- Maximum Curve Output {BasedOnField A4}", | ||
" Dimensionless, !- Input Unit Type for v", | ||
" Dimensionless, !- Input Unit Type for w", | ||
" Dimensionless, !- Input Unit Type for x", | ||
" Dimensionless, !- Input Unit Type for y", | ||
" Dimensionless; !- Input Unit Type for z", | ||
}), | ||
"Minimum Value of z [0.80] > Maximum Value of z [0.50]"}), | ||
[](const testing::TestParamInfo<CurveManagerValidationFixture::ParamType> &info) -> std::string { | ||
auto object_name = info.param.object_name; | ||
std::replace_if(object_name.begin(), object_name.end(), [](char c) { return !std::isalnum(c); }, '_'); | ||
return object_name + "_" + info.param.tested_dim; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instantiate the parametrized test. Test was prepared via https://gist.github.com/jmarrec/f86c5dd911568cb08aa293479d1a59a3
@@ -218,7 +218,7 @@ bool EnergyPlusFixture::compare_err_stream_substring(std::string const &search_s | |||
{ | |||
auto const stream_str = this->err_stream->str(); | |||
bool const found = stream_str.find(search_string) != std::string::npos; | |||
EXPECT_TRUE(found); | |||
EXPECT_TRUE(found) << "Not found in:" << "\n" << stream_str; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh excellent.
@@ -152,7 +152,7 @@ protected: | |||
|
|||
// This function creates a string based on a vector of string inputs that is delimited by DataStringGlobals::NL by default, but any | |||
// delimiter can be passed in to this function. This allows for cross platform output string comparisons. | |||
std::string delimited_string(std::vector<std::string> const &strings, std::string const &delimiter = "\n"); | |||
static std::string delimited_string(std::vector<std::string> const &strings, std::string const &delimiter = "\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kinda needed it be static, and it can be, so...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. OK. I would have thought you could work around it without this change, but also it's fine.
@@ -703,7 +703,7 @@ namespace Curve { | |||
if (Numbers(7) > Numbers(8)) { // error | |||
ShowSevereError(state, format("GetCurveInput: For {}: ", CurrentModuleObject)); | |||
ShowContinueError(state, | |||
format("{} [{:.R2}] > {} [{.R2}]", | |||
format("{} [{:.2R}] > {} [{:.2R}]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixups
@@ -218,7 +218,7 @@ bool EnergyPlusFixture::compare_err_stream_substring(std::string const &search_s | |||
{ | |||
auto const stream_str = this->err_stream->str(); | |||
bool const found = stream_str.find(search_string) != std::string::npos; | |||
EXPECT_TRUE(found); | |||
EXPECT_TRUE(found) << "Not found in:" << "\n" << stream_str; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh excellent.
@@ -152,7 +152,7 @@ protected: | |||
|
|||
// This function creates a string based on a vector of string inputs that is delimited by DataStringGlobals::NL by default, but any | |||
// delimiter can be passed in to this function. This allows for cross platform output string comparisons. | |||
std::string delimited_string(std::vector<std::string> const &strings, std::string const &delimiter = "\n"); | |||
static std::string delimited_string(std::vector<std::string> const &strings, std::string const &delimiter = "\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. OK. I would have thought you could work around it without this change, but also it's fine.
Thanks @jmarrec ! |
Pull request overview
The main problem file was CurveManager so I focused on it. It also was incorrectly checking the Minimum Input Value of <x,y,z> was <= Maximum Input Value of <x,y,z> so I specifically tested for it.
Pull Request Author
Reviewer