From ba7716cb60bad10b892f834e1b1175d81926565f Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 3 Sep 2022 04:32:27 +0200 Subject: variable radix conversion: Overload for int64_t `dec_to_radix()`, validate base, enhance tests --- test/test_basictypeconv.cpp | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'test/test_basictypeconv.cpp') diff --git a/test/test_basictypeconv.cpp b/test/test_basictypeconv.cpp index 4978b7c..1dab771 100644 --- a/test/test_basictypeconv.cpp +++ b/test/test_basictypeconv.cpp @@ -388,7 +388,7 @@ TEST_CASE( "Integer Type Test Test 05", "[integer][type]" ) { REQUIRE( 3_unz == (jau::nsize_t)3 ); } -static void testRadix(const int base) { +static void testRadix32(const int base) { { // UTF-8 (or codepage 437) <-> ASCII collision const std::string s1 = "Ç"; @@ -444,12 +444,47 @@ static void testRadix(const int base) { } } +static void testRadix64(const int base, const int64_t min, const int64_t max) { + const int padding = 9; + const std::string r1_max = jau::dec_to_radix(base-1, base, padding, '0'); + + fprintf(stderr, "Test base %d: [%" PRIi64 " .. %" PRIi64 "] <-> ['%s' .. '%s'], %" PRIi64 " years (max/365d) \n", + base, min, max, jau::dec_to_radix(min, base).c_str(), jau::dec_to_radix(max, base).c_str(), (max/365)); + + REQUIRE(0 == jau::radix_to_dec("000", base)); + REQUIRE("0" == jau::dec_to_radix(0, base)); + + REQUIRE(1 == jau::radix_to_dec("001", base)); + REQUIRE("1" == jau::dec_to_radix(1, base)); + { + const int64_t v0_d = jau::radix_to_dec(r1_max, base); + const std::string v1_s = jau::dec_to_radix(base-1, base, padding, '0'); + REQUIRE(r1_max == v1_s); + REQUIRE(base-1 == v0_d); + } + for(int64_t iter=std::max(0_i64, min-1); iter