Add a random numbers test with a fixed seed.

This commit is contained in:
King_DuckZ 2018-07-29 11:17:59 +01:00
parent 14954a3816
commit 5953ea7cb5
2 changed files with 24 additions and 0 deletions

View file

@ -296,6 +296,12 @@ namespace dhandy {
std::string to_string (I num) {
return std::string(int_to_ary(num).to_string_view());
}
template <std::size_t S>
std::string operator+ (std::string a, const ReversedSizedArray<char, S>& b) {
a.append(b.data(), b.size() - 1);
return a;
}
#endif
} //namespace dhandy

View file

@ -21,6 +21,8 @@
#include "sprout/cstring/strlen.hpp"
#include "sprout/preprocessor/comma.hpp"
#include <cstdint>
#include <random>
#include <string>
template <typename T> using int_info_10 = dhandy::implem::int_info<T, 10>;
template <typename T> using int_info_16 = dhandy::implem::int_info<T, 16>;
@ -109,6 +111,22 @@ TEST_CASE ("Check int to char array conversions", "[s2i][int_conv]") {
num = 0xFFFFFFFFFFFFFFFF;
CHECK(int_to_ary<__int128_t SPROUT_PP_COMMA() 16>(num * 0x10000 + 0xffff) == "ffffffffffffffffffff");
#endif
{
//Try a random test, which should not compile as constexpr
std::mt19937 gen;
gen.seed(1234);
for (int z = 0; z < 10; ++z) {
const int num = gen();
CHECK(int_to_ary(num) == std::to_string(num));
}
const int num = gen();
std::string hello = "hello world";
std::string hello1 = hello + " " + int_to_ary(num);
std::string hello2 = hello + " " + std::to_string(num);
CHECK(hello1 == hello2);
}
}
TEST_CASE ("Check char array to int conversions", "[i2s][int_conv]") {