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

Add unit tests to see coverage increase #2267

Merged
merged 10 commits into from
Jul 25, 2024
Merged

Add unit tests to see coverage increase #2267

merged 10 commits into from
Jul 25, 2024

Conversation

payetvin
Copy link
Contributor

No description provided.

@payetvin payetvin added the tests label Jul 16, 2024
@payetvin payetvin self-assigned this Jul 16, 2024
@payetvin payetvin marked this pull request as ready for review July 17, 2024 10:17
@flomnes flomnes closed this Jul 17, 2024
@flomnes flomnes deleted the feature/unit-tests branch July 17, 2024 14:09
@flomnes flomnes restored the feature/unit-tests branch July 18, 2024 07:50
@flomnes flomnes reopened this Jul 18, 2024
@@ -1326,6 +1326,7 @@ void Study::resizeAllTimeseriesNumbers(uint n)
bindingConstraintsGroups.resizeAllTimeseriesNumbers(n);
}

// TODO VP: Could be removed with the GUI
Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently, one call to Study :: checkForFilenameLimits(...) will remain after old GUI is removed : the one inside Application :: readDataForTheStudy(...) :

if (!study.checkForFilenameLimits(true))
{
    throw Error::InvalidFileName(); 
}

So I guess the second argument will have to be removed, as it will be useless.

@@ -1326,6 +1326,7 @@ void Study::resizeAllTimeseriesNumbers(uint n)
bindingConstraintsGroups.resizeAllTimeseriesNumbers(n);
}

// TODO VP: Could be removed with the GUI
bool Study::checkForFilenameLimits(bool output, const String& chfolder) const
Copy link
Contributor

@guilpier-code guilpier-code Jul 18, 2024

Choose a reason for hiding this comment

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

This function's code could really be improved.

  • As @payetvin says, some usage / calls of he function will be given up when dropping the old GUI, allowing first code simplifications (see comment above).

  • it's unclear : for example, boolean output argument actually tells the function :

    • if true : to evaluate the max path length of simulation results files or , but it's not obvious at all.
    • if false : not do the previous thing, but rather evaluate max path length of the input files. Not obvious.

    To know that, you have to read the code carefully.

  • Function is too large : it has too many responsibilities. At least, it should be split into 2 functions ; one for input, one for output. Besides, it has 200 lines, and mixes, at the same levels, important steps and their details.

  • it's not maintainable : what if we add new input to our studies or new output to your simulation results ? We will have to modify this function each time. That's the reason why files were forgotten in this inspection.

  • It's incomplete : what about files related to short term storage, wind, ... ?

  • Lack of simplicity : for input inspection, std::filesystem::recursive_directory_iterator could have been used instead to iterate over existing files recursively and store the largest file path. the code for that would have been much shorter.

  • probably wrong : for output processing (which should remain after old GUI is removed), it's assumed that the longest file path occurs for a file value-hourly.txt somewhere in mc-all. Are we sure of that ? First, string mc-ind is longer than mc-all. Second, what about details files (for instance details-STstorage-monthly.txt) ? Aren't their path longer than value-hourly.txt paths ?

Copy link
Contributor

@guilpier-code guilpier-code Jul 19, 2024

Choose a reason for hiding this comment

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

Finally, we might be able to remove completely this function in Win by enabling long path : see this article

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The input part is not useful without the GUI, should just be removed

That leaves only the output part and thus the areaName and linkname to check
Area name is already limited to a size of 128, this leaves only linkname (which is areaname + areaname)

As it's a windows only problem it should not be handled here anyway

@@ -291,4 +291,20 @@ BOOST_AUTO_TEST_CASE(version_parsing)
BOOST_CHECK(!v.fromString("4.5"));
BOOST_CHECK(v == StudyVersion::unknown());
}

BOOST_FIXTURE_TEST_CASE(check_filename_limit, OneAreaStudy)
Copy link
Contributor

Choose a reason for hiding this comment

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

Tests are normally more atomic.
Here, several things are tested in one test.
The results is that this new test has a more complex setting than it should have : it uses a fixture (which creates a study) and it creates another empty study.

This test checks 4 things.
We should create 4 smaller tests instead, one for each case, use the fixture only if a test requires it, and name these smaller tests more specifically, for clarity.

Copy link

@flomnes flomnes dismissed guilpier-code’s stale review July 25, 2024 11:22

Reviewer is right, but this is slightly out of scope

@flomnes flomnes merged commit 0359290 into develop Jul 25, 2024
8 checks passed
@flomnes flomnes deleted the feature/unit-tests branch July 25, 2024 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants