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

Feature Request: Support asymmetric range assertions #740

Open
jefflongo opened this issue Jul 10, 2024 · 2 comments
Open

Feature Request: Support asymmetric range assertions #740

jefflongo opened this issue Jul 10, 2024 · 2 comments

Comments

@jefflongo
Copy link

jefflongo commented Jul 10, 2024

Currently there is no mechanism to assert a number is between two other numbers aside from using TEST_ASSERT_X_WITHIN supports only symmetric ranges. I propose an assertion like TEST_ASSERT_X_WITHIN_RANGE(lower, upper, actual).

@mvandervoord
Copy link
Member

memo to myself: There is already greater than, less than, etc... therefore no additional actual functions are needed. A macro could cover this with back to back existing calls.

@jefflongo
Copy link
Author

FYI, this is how I implemented it for my own uses:

#define _TEST_ASSERT_WITHIN_RANGE_MESSAGE(type, lower, upper, actual, message)                     \
    do {                                                                                           \
        TEST_ASSERT_GREATER_OR_EQUAL_##type##_MESSAGE(lower, actual, message);                     \
        TEST_ASSERT_LESS_OR_EQUAL_##type##_MESSAGE(upper, actual, message);                        \
    } while (0)
    
#define TEST_ASSERT_WITHIN_RANGE_INT8_MESSAGE(lower, upper, actual, message)                       \
    _TEST_ASSERT_WITHIN_RANGE_MESSAGE(INT8, lower, upper, actual, message)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants