From 7f45e5938b509a76838af2c885c42eeecf82ff91 Mon Sep 17 00:00:00 2001 From: uselessgoddess Date: Sat, 4 Sep 2021 17:47:55 +0300 Subject: [PATCH] [C++] 0.1.0 --- cpp/CMakeLists.txt | 2 +- .../RandomExtensionsTests.cpp | 4 ++-- .../Platform.Random.TemplateLibrary.nuspec | 14 +++++++++----- cpp/Platform.Random/RandomExtensions.h | 8 ++++---- cpp/Platform.Random/RandomHelpers.h | 1 + 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index a6c147f..78f67dd 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -8,7 +8,7 @@ add_library(${PROJECT_NAME}.Library INTERFACE) target_include_directories(${PROJECT_NAME}.Library INTERFACE ${PROJECT_NAME}) target_link_libraries(${PROJECT_NAME}.Library INTERFACE CONAN_PKG::platform.ranges) -if((DEFINED LINKS_PLATFORM_TESTS) AND (${LINKS_PLATFORM_TESTS})) +if(${LINKS_PLATFORM_TESTS}) add_executable(${PROJECT_NAME}.Tests ${PROJECT_NAME}.Tests/AllTests.cpp) target_link_libraries(${PROJECT_NAME}.Tests PRIVATE ${PROJECT_NAME}.Library) target_link_libraries(${PROJECT_NAME}.Tests PRIVATE CONAN_PKG::gtest) diff --git a/cpp/Platform.Random.Tests/RandomExtensionsTests.cpp b/cpp/Platform.Random.Tests/RandomExtensionsTests.cpp index 16e808a..a0d4a94 100644 --- a/cpp/Platform.Random.Tests/RandomExtensionsTests.cpp +++ b/cpp/Platform.Random.Tests/RandomExtensionsTests.cpp @@ -18,8 +18,8 @@ } std::uint64_t temp = NextUInt64(RandomHelpers::Default, {0UL, 5UL}); - ASSERT_LT(temp, 5UL); - ASSERT_GT(temp, 0UL); + ASSERT_LE(temp, 5UL); + ASSERT_GE(temp, 0UL); } ASSERT_LT(theSameCount, 8); } diff --git a/cpp/Platform.Random/Platform.Random.TemplateLibrary.nuspec b/cpp/Platform.Random/Platform.Random.TemplateLibrary.nuspec index c8c3f7a..d843ed5 100644 --- a/cpp/Platform.Random/Platform.Random.TemplateLibrary.nuspec +++ b/cpp/Platform.Random/Platform.Random.TemplateLibrary.nuspec @@ -5,11 +5,15 @@ LinksPlatform's Platform.Random Template Library LinksPlatform's Platform.Random is a Template Library that contains helper functions and constants to work with random numbers. LinksPlatform's Platform.Random is a Template Library that contains helper functions and constants to work with random numbers. Use Platform.Random.h file to include the library. - Initial release. - 0.0.1 - konard, norwend - konard, norwend - konard, norwend + Huge bug fix: +- compile error +- stupid functions ordering +- todo static throw +- test assertions + 0.1.0 + konard, norwend, uselessgoddess + konard, norwend, uselessgoddess + konard, norwend, uselessgoddess https://linksplatform.github.io/Random images/icon.png diff --git a/cpp/Platform.Random/RandomExtensions.h b/cpp/Platform.Random/RandomExtensions.h index b6476f5..b25a3b3 100644 --- a/cpp/Platform.Random/RandomExtensions.h +++ b/cpp/Platform.Random/RandomExtensions.h @@ -1,8 +1,8 @@ namespace Platform::Random { - static std::uint64_t NextUInt64(std::mt19937_64& random) { return NextUInt64(random, Ranges::UInt64); } + std::uint64_t NextUInt64(std::mt19937_64& random, const Ranges::Range& range) { return std::uniform_int_distribution{range.Minimum, range.Maximum}(random); } - static std::uint64_t NextUInt64(std::mt19937_64& random, const Range& range) { return std::uniform_int_distribution{range.Minimum, range.Maximum}(random); } + std::uint64_t NextUInt64(std::mt19937_64& random) { return NextUInt64(random, Ranges::UInt64); } - static bool NextBoolean(std::mt19937_64& random) { return std::uniform_int_distribution{0, 1}(random); } -} // namespace Platform::Random + bool NextBoolean(std::mt19937_64& random) { return std::uniform_int_distribution{}(random) % 2 == 0; } +} diff --git a/cpp/Platform.Random/RandomHelpers.h b/cpp/Platform.Random/RandomHelpers.h index 16b5499..fc703b7 100644 --- a/cpp/Platform.Random/RandomHelpers.h +++ b/cpp/Platform.Random/RandomHelpers.h @@ -1,4 +1,5 @@ namespace Platform::Random::RandomHelpers { + // FIXME: cert-err58-cpp std::mt19937_64 Default { std::random_device{}() }; }