diff options
author | Roland Reichwein <mail@reichwein.it> | 2022-01-06 12:32:59 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2022-01-06 12:32:59 +0100 |
commit | fceee089c114e8510fd1e7f06f258b5d67cf23bf (patch) | |
tree | 9742f1be327bf1beac26246cb58afcf230a9202c | |
parent | 5ad6e853eaee2533f934575b8509e0e0c5da12e5 (diff) |
Fix division by 0 in performance test
-rw-r--r-- | src/test-performance.cpp | 8 |
1 files 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<typename T> T generate_value(T max = std::numeric_limits<T>::max()) { - uint64_t max_modulo{ static_cast<uint64_t>(0x100000000ULL) - (0x100000000ULL % (max + 1))}; + BOOST_REQUIRE_LE(max, 0xFFFFFFFFFFFFFFFF); + + uint64_t max_modulo{ static_cast<uint64_t>(0x100000000ULL) - (0x100000000ULL % (static_cast<uint64_t>(max) + 1))}; uint32_t value{}; do { @@ -59,7 +61,7 @@ T generate_value(T max = std::numeric_limits<T>::max()) } } while (static_cast<uint64_t>(value) >= max_modulo); - return static_cast<T>(value % (max + 1)); + return static_cast<T>(value % (static_cast<uint64_t>(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<typename From, typename ToTypesCollectionType, size_t i = 0> void test_string_invalid(size_t length) { - //std::cerr << "LENGTH: " << length << std::endl; typedef typename std::tuple_element<i,ToTypesCollectionType>::type To; From r {static_cast<From>(generate_string_invalid<From>(length))}; @@ -196,6 +197,7 @@ void test_string_valid(char32_t max, size_t length, const std::string& descripti return unicode::convert<unicode::UTF_32, typename unicode::Encoding_t<typename From::value_type>>(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<typename From::value_type>,typename unicode::Encoding_t<typename To::value_type>>(list[i])}; |