Translated tests for Random/RandomRange
This commit is contained in:
parent
c5cf1c0061
commit
4a9b59e2d8
@ -23,9 +23,11 @@ add_executable(Tests
|
|||||||
Vector2.cpp
|
Vector2.cpp
|
||||||
Vector3.cpp
|
Vector3.cpp
|
||||||
Vector4.cpp
|
Vector4.cpp
|
||||||
|
VectorConversion.cpp
|
||||||
Quaternion.cpp
|
Quaternion.cpp
|
||||||
Random__RandomFloat.cpp
|
Random__RandomFloat.cpp
|
||||||
VectorConversion.cpp
|
Random__RandomInteger.cpp
|
||||||
|
Random__RandomRange.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(Tests Eule)
|
target_link_libraries(Tests Eule)
|
||||||
|
@ -1,51 +1,42 @@
|
|||||||
#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>
|
|
||||||
|
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
||||||
using namespace Eule;
|
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)
|
// Setup
|
||||||
{
|
std::vector<unsigned int> rands;
|
||||||
public:
|
rands.resize(1000);
|
||||||
// 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);
|
|
||||||
|
|
||||||
// Exercise
|
// Exercise
|
||||||
// Create 1000 random values
|
// Create 1000 random values
|
||||||
std::generate_n(rands.data(), rands.size(), []()->unsigned int { return Random::RandomUint(); });
|
std::generate_n(rands.data(), rands.size(), []()->unsigned int { return Random::RandomUint(); });
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
const double stddev = Testutil::Stddev<unsigned int>(rands);
|
const double stddev = Testutil::Stddev<unsigned int>(rands);
|
||||||
Assert::IsTrue(stddev >= 1000000, (std::wstringstream() << stddev).str().c_str());
|
REQUIRE(stddev >= 1000000);
|
||||||
|
|
||||||
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(Int_Big_Standard_Deviation)
|
TEST_CASE(__FILE__"/Int_Big_Standard_Deviation", "[Random][RandomInt]")
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
std::vector<int> rands;
|
std::vector<int> rands;
|
||||||
rands.resize(1000);
|
rands.resize(1000);
|
||||||
|
|
||||||
// Exercise
|
// Exercise
|
||||||
// Create 1000 random values
|
// Create 1000 random values
|
||||||
std::generate_n(rands.data(), rands.size(), []()->int { return Random::RandomInt(); });
|
std::generate_n(rands.data(), rands.size(), []()->int { return Random::RandomInt(); });
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
const double stddev = Testutil::Stddev<int>(rands);
|
const double stddev = Testutil::Stddev<int>(rands);
|
||||||
Assert::IsTrue(stddev >= 1000000, (std::wstringstream() << stddev).str().c_str());
|
REQUIRE(stddev >= 1000000);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@ -1,79 +1,75 @@
|
|||||||
#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>
|
|
||||||
|
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
||||||
using namespace Eule;
|
using namespace Eule;
|
||||||
|
|
||||||
namespace _Random
|
// Checks that a random double is never outside the specification, two positive values
|
||||||
|
TEST_CASE(__FILE__"/Random_Doublerange_Never_Outside_Specification__pos__pos", "[Random][RandomRange]")
|
||||||
{
|
{
|
||||||
TEST_CLASS(_RandomRange)
|
// Test 1000 random integers
|
||||||
{
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
public:
|
{
|
||||||
|
double rnd = Random::RandomRange(49.0, 99.0);
|
||||||
|
|
||||||
// Checks that a random double is never outside the specification, two positive values
|
INFO("rnd too small");
|
||||||
TEST_METHOD(Random_Doublerange_Never_Outside_Specification__pos__pos)
|
REQUIRE(rnd >= 49.0);
|
||||||
{
|
INFO("rnd too big");
|
||||||
// Test 1000 random integers
|
REQUIRE(rnd <= 99.0);
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
}
|
||||||
{
|
|
||||||
double rnd = Random::RandomRange(49.0, 99.0);
|
|
||||||
|
|
||||||
Assert::IsTrue(rnd >= 49.0, L"rnd too small");
|
return;
|
||||||
Assert::IsTrue(rnd <= 99.0, L"rnd too big");
|
}
|
||||||
}
|
|
||||||
|
// Checks that a random double is never outside the specification, negative minimum
|
||||||
return;
|
TEST_CASE(__FILE__"/Random_Doublerange_Never_Outside_Specification__neg__pos", "[Random][RandomRange]")
|
||||||
}
|
{
|
||||||
|
// Test 1000 random integers
|
||||||
// Checks that a random double is never outside the specification, negative minimum
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
TEST_METHOD(Random_Doublerange_Never_Outside_Specification__neg__pos)
|
{
|
||||||
{
|
double rnd = Random::RandomRange(-39.0, 99.0);
|
||||||
// Test 1000 random integers
|
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
INFO("rnd too small");
|
||||||
{
|
REQUIRE(rnd >= -39.0);
|
||||||
double rnd = Random::RandomRange(-39.0, 99.0);
|
INFO("rnd too big");
|
||||||
|
REQUIRE(rnd <= 99.0);
|
||||||
Assert::IsTrue(rnd >= -39.0, L"rnd too small");
|
}
|
||||||
Assert::IsTrue(rnd <= 99.0, L"rnd too big");
|
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
return;
|
|
||||||
}
|
// Checks that a random double is never outside the specification, two negative values
|
||||||
|
TEST_CASE(__FILE__"/Random_Doublerange_Never_Outside_Specification__neg__neg", "[Random][RandomRange]")
|
||||||
// Checks that a random double is never outside the specification, two negative values
|
{
|
||||||
TEST_METHOD(Random_Doublerange_Never_Outside_Specification__neg__neg)
|
// Test 1000 random integers
|
||||||
{
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
// Test 1000 random integers
|
{
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
double rnd = Random::RandomRange(-39.0, -10.0);
|
||||||
{
|
|
||||||
double rnd = Random::RandomRange(-39.0, -10.0);
|
INFO("rnd too small");
|
||||||
|
REQUIRE(rnd >= -39.0);
|
||||||
Assert::IsTrue(rnd >= -39.0, L"rnd too small");
|
INFO("rnd too big");
|
||||||
Assert::IsTrue(rnd <= -10.0, L"rnd too big");
|
REQUIRE(rnd <= -10.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks that the produced double-precision floating point distribution shows a big standard deviation
|
// Checks that the produced double-precision floating point distribution shows a big standard deviation
|
||||||
TEST_METHOD(Double_Big_Standard_Deviation)
|
TEST_CASE(__FILE__"/Double_Big_Standard_Deviation", "[Random][RandomRange]")
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
std::vector<double> rands;
|
std::vector<double> rands;
|
||||||
rands.resize(100);
|
rands.resize(100);
|
||||||
|
|
||||||
// Exercise
|
// Exercise
|
||||||
// Create 1000 random values
|
// Create 1000 random values
|
||||||
std::generate_n(rands.data(), rands.size(), []()->double { return Random::RandomRange(100, 4e9); });
|
std::generate_n(rands.data(), rands.size(), []()->double { return Random::RandomRange(100, 4e9); });
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
const double stddev = Testutil::Stddev(rands);
|
const double stddev = Testutil::Stddev(rands);
|
||||||
Assert::IsTrue(stddev >= 1000000, (std::wstringstream() << stddev).str().c_str());
|
REQUIRE(stddev >= 1000000);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user