#include <iostream>
#include <cassert>
#include <cinttypes>
#include <cstring>
#define CATCH_CONFIG_MAIN
#include <catch2/catch_amalgamated.hpp>
#define SHOW_DECIMAL_STRING_STATS 0
#if SHOW_DECIMAL_STRING_STATS
template<class T>
void show_decimal_string_stats(const std::string msg, const T value, const bool use_separator, const int min_width) {
const nsize_t max_digits10 = std::numeric_limits<T>::is_signed ?
jau::digits10<T>(std::numeric_limits<T>::min()) :
jau::digits10<T>(std::numeric_limits<T>::max());
const T max_value = std::numeric_limits<T>::max();
const T min_value = std::numeric_limits<T>::min();
const nsize_t max_digits10_1 = jau::digits10<T>(min_value);
const nsize_t max_digits10_2 = jau::digits10<T>(max_value);
const nsize_t max_commas = use_separator ? ( max_digits10 - 1 ) / 3 : 0;
const nsize_t max_chars = max_digits10 + max_commas;
const nsize_t digit10_count = jau::digits10<T>(value);
const nsize_t comma_count = use_separator ? ( digit10_count - 1 ) / 3 : 0;
const nsize_t net_chars = digit10_count + comma_count;
const nsize_t total_chars = std::min<nsize_t>(max_chars, std::max<nsize_t>(min_width, net_chars));
std::string s = to_decstring<T>(value, use_separator ? ',' : 0, min_width);
}
#endif
static void test_int32_t(
const std::string msg,
const int32_t v,
const size_t expStrLen,
const std::string expStr) {
#if SHOW_DECIMAL_STRING_STATS
show_decimal_string_stats<int32_t>(msg, v, true , 0 );
#endif
REQUIRE(str.length() == expStrLen);
REQUIRE_THAT(str, Catch::Matchers::Equals(expStr, Catch::CaseSensitive::Yes));
}
static void test_uint32_t(
const std::string msg,
const uint32_t v,
const size_t expStrLen,
const std::string expStr) {
#if SHOW_DECIMAL_STRING_STATS
show_decimal_string_stats<uint32_t>(msg, v, true , 0 );
#endif
REQUIRE(str.length() == expStrLen);
REQUIRE_THAT(str, Catch::Matchers::Equals(expStr, Catch::CaseSensitive::Yes));
}
static void test_uint64_t(
const std::string msg,
const uint64_t v,
const size_t expStrLen,
const std::string expStr) {
#if SHOW_DECIMAL_STRING_STATS
show_decimal_string_stats<uint64_t>(msg, v, true , 0 );
#endif
REQUIRE(str.length() == expStrLen);
REQUIRE_THAT(str, Catch::Matchers::Equals(expStr, Catch::CaseSensitive::Yes));
}
TEST_CASE(
"Integer Decimal String Test 01",
"[datatype][int_dec_string]" ) {
test_uint64_t(
"UINT64_MAX", UINT64_MAX, 26,
"18,446,744,073,709,551,615");
}