Translated tests for Random/RandomIntRange
This commit is contained in:
parent
4a9b59e2d8
commit
7675422264
@ -28,6 +28,7 @@ add_executable(Tests
|
|||||||
Random__RandomFloat.cpp
|
Random__RandomFloat.cpp
|
||||||
Random__RandomInteger.cpp
|
Random__RandomInteger.cpp
|
||||||
Random__RandomRange.cpp
|
Random__RandomRange.cpp
|
||||||
|
Random_RandomIntRange.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(Tests Eule)
|
target_link_libraries(Tests Eule)
|
||||||
|
@ -1,64 +1,64 @@
|
|||||||
#include "CppUnitTest.h"
|
#include "Catch2.h"
|
||||||
#include "../_TestingUtilities/Testutil.h"
|
#include "../_TestingUtilities/Testutil.h"
|
||||||
#include "../Eule/Random.h"
|
#include <Eule/Random.h>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
||||||
using namespace Eule;
|
using namespace Eule;
|
||||||
|
|
||||||
namespace _Random
|
|
||||||
{
|
|
||||||
TEST_CLASS(_RandomIntRange)
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// Checks that a random integer is never outside the specification, two positive values
|
// Checks that a random integer is never outside the specification, two positive values
|
||||||
TEST_METHOD(Never_Outside_Specification__pos__pos)
|
TEST_CASE(__FILE__"/Never_Outside_Specification__pos__pos", "[Random][RandomIntRange]")
|
||||||
{
|
{
|
||||||
// Test 1000 random integers
|
// Test 1000 random integers
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
{
|
{
|
||||||
int rnd = Random::RandomIntRange(49, 99);
|
int rnd = Random::RandomIntRange(49, 99);
|
||||||
|
|
||||||
Assert::IsTrue(rnd >= 49, L"rnd too small");
|
INFO("rnd too small");
|
||||||
Assert::IsTrue(rnd <= 99, L"rnd too big");
|
REQUIRE(rnd >= 49);
|
||||||
|
INFO("rnd too big");
|
||||||
|
REQUIRE(rnd <= 99);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks that a random integer is never outside the specification, negative minimum
|
// Checks that a random integer is never outside the specification, negative minimum
|
||||||
TEST_METHOD(Never_Outside_Specification__neg__pos)
|
TEST_CASE(__FILE__"/Never_Outside_Specification__neg__pos", "[Random][RandomIntRange]")
|
||||||
{
|
{
|
||||||
// Test 1000 random integers
|
// Test 1000 random integers
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
{
|
{
|
||||||
int rnd = Random::RandomIntRange(-39, 99);
|
int rnd = Random::RandomIntRange(-39, 99);
|
||||||
|
|
||||||
Assert::IsTrue(rnd >= -39, L"rnd too small");
|
INFO("rnd too small");
|
||||||
Assert::IsTrue(rnd <= 99, L"rnd too big");
|
REQUIRE(rnd >= -39);
|
||||||
|
INFO("rnd too big");
|
||||||
|
REQUIRE(rnd <= 99);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks that a random integer is never outside the specification, two negative values
|
// Checks that a random integer is never outside the specification, two negative values
|
||||||
TEST_METHOD(Never_Outside_Specification__neg__neg)
|
TEST_CASE(__FILE__"/Never_Outside_Specification__neg__neg", "[Random][RandomIntRange]")
|
||||||
{
|
{
|
||||||
// Test 1000 random integers
|
// Test 1000 random integers
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
{
|
{
|
||||||
int rnd = Random::RandomIntRange(-39, -10);
|
int rnd = Random::RandomIntRange(-39, -10);
|
||||||
|
|
||||||
Assert::IsTrue(rnd >= -39, L"rnd too small");
|
INFO("rnd too small");
|
||||||
Assert::IsTrue(rnd <= -10, L"rnd too big");
|
REQUIRE(rnd >= -39);
|
||||||
|
INFO("rnd too big");
|
||||||
|
REQUIRE(rnd <= -10);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks that the random intrange method also returns the supplied limits
|
// Checks that the random intrange method also returns the supplied limits
|
||||||
TEST_METHOD(Inclusivity)
|
TEST_CASE(__FILE__"/Inclusivity", "[Random][RandomIntRange]")
|
||||||
{
|
{
|
||||||
// Test 1000 random integers
|
// Test 1000 random integers
|
||||||
// The chance that any number [0,9] will not drop at least once is basically 0
|
// The chance that any number [0,9] will not drop at least once is basically 0
|
||||||
@ -74,13 +74,13 @@ namespace _Random
|
|||||||
|
|
||||||
// Check that each value has been rolled at least once
|
// Check that each value has been rolled at least once
|
||||||
for (const bool& b : foundDigits)
|
for (const bool& b : foundDigits)
|
||||||
Assert::IsTrue(b);
|
REQUIRE(b);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks that the produced integer distribution shows a big standard deviation
|
// Checks that the produced integer distribution shows a big standard deviation
|
||||||
TEST_METHOD(Big_Standard_Deviation)
|
TEST_CASE(__FILE__"/Big_Standard_Deviation", "[Random][RandomIntRange]")
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
std::vector<int> rands;
|
std::vector<int> rands;
|
||||||
@ -91,10 +91,16 @@ namespace _Random
|
|||||||
std::generate_n(rands.data(), rands.size(), []()->int { return Random::RandomIntRange(100, (int)4e9); });
|
std::generate_n(rands.data(), rands.size(), []()->int { return Random::RandomIntRange(100, (int)4e9); });
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "[";
|
||||||
|
for (int i : rands)
|
||||||
|
ss << i << ", ";
|
||||||
|
ss << "]";
|
||||||
|
|
||||||
const double stddev = Testutil::Stddev(rands);
|
const double stddev = Testutil::Stddev(rands);
|
||||||
Assert::IsTrue(stddev >= 1000000, (std::wstringstream() << stddev).str().c_str());
|
INFO(ss.str());
|
||||||
|
REQUIRE(stddev >= 1000000);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user