Skip to content

Fixed calculate_max_string_length unit test to work in CLion #1447

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,31 @@ SCENARIO("calculate_max_string_length",
signedbv_typet(32),
unsignedbv_typet(32),
signedbv_typet(64),
unsignedbv_typet(64)};
unsignedbv_typet(64),
};

for(const typet &type : int_types)
{
WHEN(std::string("type = ")+type.pretty())
std::string type_str=type.pretty();
std::replace(type_str.begin(), type_str.end(), '\n', ' ');
WHEN("type = "+type_str)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is the best way to output extra info - Catch provides logging macros and there is support for using INFO on irept: (see unit_tests.cpp). (non-blocking)

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 think this is the WHEN for this test rather than just a logging message.

{
for(const unsigned long radix : radixes)
{
WHEN(std::string("radix = ")+std::to_string(radix))
WHEN("radix = "+std::to_string(radix))
{
size_t actual_value=max_printed_string_length(type, radix);
WHEN(std::string("correct value")+type.pretty())
THEN("value is correct")
{
size_t expected_value=expected_length(radix, type);
/// Due to floating point rounding errors, we sometime get one more
/// than the actual value, which is perfectly fine for our purposes
REQUIRE(expected_value<=actual_value);
REQUIRE(expected_value+1>=actual_value);
// Due to floating point rounding errors, we sometime get one more
// than the actual value, which is perfectly fine for our purposes
// Double brackets here prevent Catch trying to decompose a
// complex expression
REQUIRE((
actual_value==expected_value || actual_value==expected_value+1));
}
WHEN(std::string("value is less than with default radix"))
THEN("value is no greater than with default radix")
{
size_t actual_value_for_default=max_printed_string_length(type, 0);
REQUIRE(actual_value<=actual_value_for_default);
Expand Down