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

Change randomValue function's maximum value #251

Open
ihhub opened this issue Nov 10, 2018 · 1 comment · May be fixed by #565
Open

Change randomValue function's maximum value #251

ihhub opened this issue Nov 10, 2018 · 1 comment · May be fixed by #565
Labels
good first issue An issue is perfectly suitable for first comers. A very minimal knowledge of the project is required help wanted We need a help improvement Upgrade existing feature performance tests Project related performance tests unit tests Project related unit tests
Milestone

Comments

@ihhub
Copy link
Owner

ihhub commented Nov 10, 2018

We have a function randomValue template function in unit and performance tests (test/unit_tests/unit_test_helper.h and test/performance_tests/performance_test_helper.h) which has a body:

    template <typename data>
    data randomValue( data minimum, int maximum )
    {
        if( maximum <= 0 ) {
            return 0;
        }
        else {
            data value = static_cast<data>(rand() % maximum);

            if( value < minimum )
                value = minimum;

            return value;
        }
    }

This function leads to misunderstand because maximum value is actually a limit which cannot be reached. There are multiple possible solutions to this problem:

  1. Change rand() % maximum to rand() % (maximum + 1). After this we have to change all calls of this function.
  2. Change maximum variable name to something more understandable
  3. Add new functions which can use a full range of values for specific type of variables. For example:
bool randomBool();
uint8_t randomUint8_t();

Then we would cover almost all cases for initial function usage.

@ihhub ihhub added improvement Upgrade existing feature unit tests Project related unit tests performance tests Project related performance tests labels Nov 10, 2018
@ihhub ihhub added this to the Whishlist milestone Nov 10, 2018
@ihhub
Copy link
Owner Author

ihhub commented Nov 10, 2018

This issue relates to #249

@yannlabou yannlabou added help wanted We need a help good first issue An issue is perfectly suitable for first comers. A very minimal knowledge of the project is required labels Nov 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue An issue is perfectly suitable for first comers. A very minimal knowledge of the project is required help wanted We need a help improvement Upgrade existing feature performance tests Project related performance tests unit tests Project related unit tests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants