Translated tests for Random/RandomRange

This commit is contained in:
Leonetienne
2022-02-11 15:26:10 +01:00
parent c5cf1c0061
commit 4a9b59e2d8
3 changed files with 101 additions and 112 deletions

View File

@@ -1,51 +1,42 @@
#include "CppUnitTest.h"
#include "Catch2.h"
#include "../_TestingUtilities/Testutil.h"
#include "../Eule/Random.h"
#include <Eule/Random.h>
#include <array>
#include <sstream>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Eule;
namespace _Random
// Checks that the produced unsigned-integer distribution shows a big standard deviation
TEST_CASE(__FILE__"/Uint_Big_Standard_Deviation", "[Random][RandomInt]")
{
TEST_CLASS(_RandomInteger)
{
public:
// Checks that the produced unsigned-integer distribution shows a big standard deviation
TEST_METHOD(Uint_Big_Standard_Deviation)
{
// Setup
std::vector<unsigned int> rands;
rands.resize(1000);
// Setup
std::vector<unsigned int> rands;
rands.resize(1000);
// Exercise
// Create 1000 random values
std::generate_n(rands.data(), rands.size(), []()->unsigned int { return Random::RandomUint(); });
// Exercise
// Create 1000 random values
std::generate_n(rands.data(), rands.size(), []()->unsigned int { return Random::RandomUint(); });
// Verify
const double stddev = Testutil::Stddev<unsigned int>(rands);
Assert::IsTrue(stddev >= 1000000, (std::wstringstream() << stddev).str().c_str());
// Verify
const double stddev = Testutil::Stddev<unsigned int>(rands);
REQUIRE(stddev >= 1000000);
return;
}
// Checks that the produced integer distribution shows a big standard deviation
TEST_METHOD(Int_Big_Standard_Deviation)
{
// Setup
std::vector<int> rands;
rands.resize(1000);
// Exercise
// Create 1000 random values
std::generate_n(rands.data(), rands.size(), []()->int { return Random::RandomInt(); });
// Verify
const double stddev = Testutil::Stddev<int>(rands);
Assert::IsTrue(stddev >= 1000000, (std::wstringstream() << stddev).str().c_str());
return;
}
};
return;
}
// Checks that the produced integer distribution shows a big standard deviation
TEST_CASE(__FILE__"/Int_Big_Standard_Deviation", "[Random][RandomInt]")
{
// Setup
std::vector<int> rands;
rands.resize(1000);
// Exercise
// Create 1000 random values
std::generate_n(rands.data(), rands.size(), []()->int { return Random::RandomInt(); });
// Verify
const double stddev = Testutil::Stddev<int>(rands);
REQUIRE(stddev >= 1000000);
return;
}