Skip to content
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

Merged
merged 8 commits into from
Feb 4, 2025

Conversation

jmarrec
Copy link
Contributor

@jmarrec jmarrec commented Jan 28, 2025

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

  • Title of PR should be user-synopsis style (clearly understandable in a standalone changelog context)
  • Label the PR with at least one of: Defect, Refactoring, NewFeature, Performance, and/or DoNoPublish
  • Pull requests that impact EnergyPlus code must also include unit tests to cover enhancement or defect repair
  • Author should provide a "walkthrough" of relevant code changes using a GitHub code review comment process
  • If any diffs are expected, author must demonstrate they are justified using plots and descriptions
  • If changes fix a defect, the fix should be demonstrated in plots and descriptions
  • If any defect files are updated to a more recent version, upload new versions here or on DevSupport
  • If IDD requires transition, transition source, rules, ExpandObjects, and IDFs must be updated, and add IDDChange label
  • If structural output changes, add to output rules file and add OutputChange label
  • If adding/removing any LaTeX docs or figures, update that document's CMakeLists file dependencies

Reviewer

  • Perform a Code Review on GitHub
  • If branch is behind develop, merge develop and build locally to check for side effects of the merge
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified
  • Check that performance is not impacted (CI Linux results include performance check)
  • Run Unit Test(s) locally
  • Check any new function arguments for performance impacts
  • Verify IDF naming conventions and styles, memos and notes and defaults
  • If new idf included, locally check the err file and other outputs

@jmarrec jmarrec added Defect Includes code to repair a defect in EnergyPlus NotIDDChange Code does not impact IDD (can be merged after IO freeze) labels Jan 28, 2025
@jmarrec jmarrec requested a review from Myoldmopar January 28, 2025 17:24
@jmarrec jmarrec self-assigned this Jan 28, 2025
Comment on lines +748 to +776
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));
}
Copy link
Contributor Author

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.

Comment on lines +778 to +820
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));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parametrized test

Comment on lines 822 to 1756
" 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;
});
Copy link
Contributor Author

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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it clearer

Copy link
Member

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");
Copy link
Contributor Author

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...

Copy link
Member

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}]",
Copy link
Contributor Author

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;
Copy link
Member

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");
Copy link
Member

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.

@Myoldmopar
Copy link
Member

Thanks @jmarrec !

@Myoldmopar Myoldmopar merged commit bc2e84c into develop Feb 4, 2025
9 checks passed
@Myoldmopar Myoldmopar deleted the 10916_Broken_Format_CurveManager branch February 4, 2025 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Defect Includes code to repair a defect in EnergyPlus NotIDDChange Code does not impact IDD (can be merged after IO freeze)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken format strings in a few places like WeatherManager and CurveManager
4 participants