From 5fa0e1584380a414e435dda05fcb31d3c2be64be Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 7 Jun 2021 14:43:19 +0300 Subject: [PATCH] crypto tests: crypto_calc_lsb_32 --- tests/functional_tests/crypto_tests.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/functional_tests/crypto_tests.cpp b/tests/functional_tests/crypto_tests.cpp index ba4313fd..eaf5a5f3 100644 --- a/tests/functional_tests/crypto_tests.cpp +++ b/tests/functional_tests/crypto_tests.cpp @@ -1551,6 +1551,30 @@ TEST(crypto, hex_tools) return true; } + +TEST(crypto, calc_lsb_32) +{ + auto& local_calc_lsb = [](uint32_t v) { + uint8_t r = 0; + while (v != 0 && (v & 1) == 0) + { + v >>= 1; + ++r; + } + return r; + }; + + for (uint32_t x = 0; x < UINT32_MAX; ++x) + { + if (x % 10000000 == 0) + std::cout << x << ENDL; + ASSERT_EQ((int)local_calc_lsb(x), (int)calc_lsb_32(x)); + } + ASSERT_EQ((int)local_calc_lsb(UINT32_MAX), (int)calc_lsb_32(UINT32_MAX)); + + return true; +} + // // test's runner //