From fceee089c114e8510fd1e7f06f258b5d67cf23bf Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Thu, 6 Jan 2022 12:32:59 +0100 Subject: Fix division by 0 in performance test --- src/test-performance.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test-performance.cpp b/src/test-performance.cpp index 90397b7..26ae5d2 100644 --- a/src/test-performance.cpp +++ b/src/test-performance.cpp @@ -50,7 +50,9 @@ uint8_t generate_byte() template T generate_value(T max = std::numeric_limits::max()) { - uint64_t max_modulo{ static_cast(0x100000000ULL) - (0x100000000ULL % (max + 1))}; + BOOST_REQUIRE_LE(max, 0xFFFFFFFFFFFFFFFF); + + uint64_t max_modulo{ static_cast(0x100000000ULL) - (0x100000000ULL % (static_cast(max) + 1))}; uint32_t value{}; do { @@ -59,7 +61,7 @@ T generate_value(T max = std::numeric_limits::max()) } } while (static_cast(value) >= max_modulo); - return static_cast(value % (max + 1)); + return static_cast(value % (static_cast(max) + 1)); } // generates valid and invalid strings of different type @@ -91,7 +93,6 @@ std::u32string generate_string(char32_t max, size_t length) template void test_string_invalid(size_t length) { - //std::cerr << "LENGTH: " << length << std::endl; typedef typename std::tuple_element::type To; From r {static_cast(generate_string_invalid(length))}; @@ -196,6 +197,7 @@ void test_string_valid(char32_t max, size_t length, const std::string& descripti return unicode::convert>(s); }); + // Sanity check before performance tests for (size_t i = 0; i < list.size(); i++) { BOOST_CHECK(list[i].size() >= u32list[i].size()); To result{unicode::convert,typename unicode::Encoding_t>(list[i])}; -- cgit v1.2.3