Quicker unit tests

This commit is contained in:
Christophe Riccio 2016-11-20 23:02:20 +01:00
parent c83e38f9fb
commit 9755dea062
2 changed files with 22 additions and 24 deletions

View File

@ -2,10 +2,10 @@
#include <gli/gli.hpp>
#include <gli/gtx/loader.hpp>
std::size_t const Size = 64;
int test_simplex()
{
std::size_t const Size = 256;
{
std::vector<glm::byte> ImageData(Size * Size * 3);
@ -62,8 +62,6 @@ int test_simplex()
int test_perlin()
{
std::size_t const Size = 256;
{
std::vector<glm::byte> ImageData(Size * Size * 3);
@ -120,8 +118,6 @@ int test_perlin()
int test_perlin_pedioric()
{
std::size_t const Size = 256;
{
std::vector<glm::byte> ImageData(Size * Size * 3);

View File

@ -4,6 +4,8 @@
# include <array>
#endif
std::size_t const TestSamples = 10000;
int test_linearRand()
{
int Error = 0;
@ -15,7 +17,7 @@ int test_linearRand()
glm::u8vec2 AMin(std::numeric_limits<glm::u8>::max());
glm::u8vec2 AMax(std::numeric_limits<glm::u8>::min());
{
for(std::size_t i = 0; i < 100000; ++i)
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::u8vec2 A = glm::linearRand(glm::u8vec2(Min), glm::u8vec2(Max));
AMin = glm::min(AMin, A);
@ -36,7 +38,7 @@ int test_linearRand()
glm::u16vec2 BMin(std::numeric_limits<glm::u16>::max());
glm::u16vec2 BMax(std::numeric_limits<glm::u16>::min());
{
for(std::size_t i = 0; i < 100000; ++i)
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::u16vec2 B = glm::linearRand(glm::u16vec2(Min), glm::u16vec2(Max));
BMin = glm::min(BMin, B);
@ -57,7 +59,7 @@ int test_linearRand()
glm::u32vec2 CMin(std::numeric_limits<glm::u32>::max());
glm::u32vec2 CMax(std::numeric_limits<glm::u32>::min());
{
for(std::size_t i = 0; i < 100000; ++i)
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::u32vec2 C = glm::linearRand(glm::u32vec2(Min), glm::u32vec2(Max));
CMin = glm::min(CMin, C);
@ -78,7 +80,7 @@ int test_linearRand()
glm::u64vec2 DMin(std::numeric_limits<glm::u64>::max());
glm::u64vec2 DMax(std::numeric_limits<glm::u64>::min());
{
for(std::size_t i = 0; i < 100000; ++i)
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::u64vec2 D = glm::linearRand(glm::u64vec2(Min), glm::u64vec2(Max));
DMin = glm::min(DMin, D);
@ -101,7 +103,7 @@ int test_linearRand()
glm::i8vec2 AMin(std::numeric_limits<glm::i8>::max());
glm::i8vec2 AMax(std::numeric_limits<glm::i8>::min());
{
for(std::size_t i = 0; i < 100000; ++i)
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::i8vec2 A = glm::linearRand(glm::i8vec2(Min), glm::i8vec2(Max));
AMin = glm::min(AMin, A);
@ -122,7 +124,7 @@ int test_linearRand()
glm::i16vec2 BMin(std::numeric_limits<glm::i16>::max());
glm::i16vec2 BMax(std::numeric_limits<glm::i16>::min());
{
for(std::size_t i = 0; i < 100000; ++i)
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::i16vec2 B = glm::linearRand(glm::i16vec2(Min), glm::i16vec2(Max));
BMin = glm::min(BMin, B);
@ -143,7 +145,7 @@ int test_linearRand()
glm::i32vec2 CMin(std::numeric_limits<glm::i32>::max());
glm::i32vec2 CMax(std::numeric_limits<glm::i32>::min());
{
for(std::size_t i = 0; i < 100000; ++i)
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::i32vec2 C = glm::linearRand(glm::i32vec2(Min), glm::i32vec2(Max));
CMin = glm::min(CMin, C);
@ -164,7 +166,7 @@ int test_linearRand()
glm::i64vec2 DMin(std::numeric_limits<glm::i64>::max());
glm::i64vec2 DMax(std::numeric_limits<glm::i64>::min());
{
for(std::size_t i = 0; i < 100000; ++i)
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::i64vec2 D = glm::linearRand(glm::i64vec2(Min), glm::i64vec2(Max));
DMin = glm::min(DMin, D);
@ -183,7 +185,7 @@ int test_linearRand()
}
}
for(std::size_t i = 0; i < 100000; ++i)
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::f32vec2 const A(glm::linearRand(glm::f32vec2(static_cast<float>(Min)), glm::f32vec2(static_cast<float>(Max))));
if(!glm::all(glm::lessThanEqual(A, glm::f32vec2(static_cast<float>(Max)))))
@ -202,7 +204,7 @@ int test_linearRand()
{
float ResultFloat = 0.0f;
double ResultDouble = 0.0f;
for(std::size_t i = 0; i < 100000; ++i)
for(std::size_t i = 0; i < TestSamples; ++i)
{
ResultFloat += glm::linearRand(-1.0f, 1.0f);
ResultDouble += glm::linearRand(-1.0, 1.0);
@ -221,7 +223,7 @@ int test_circularRand()
int Error = 0;
{
std::size_t Max = 100000;
std::size_t Max = TestSamples;
float ResultFloat = 0.0f;
double ResultDouble = 0.0f;
double Radius = 2.0f;
@ -245,7 +247,7 @@ int test_sphericalRand()
int Error = 0;
{
std::size_t Max = 100000;
std::size_t Max = TestSamples;
float ResultFloatA = 0.0f;
float ResultFloatB = 0.0f;
float ResultFloatC = 0.0f;
@ -283,14 +285,14 @@ int test_diskRand()
float ResultFloat = 0.0f;
double ResultDouble = 0.0f;
for(std::size_t i = 0; i < 100000; ++i)
for(std::size_t i = 0; i < TestSamples; ++i)
{
ResultFloat += glm::length(glm::diskRand(2.0f));
ResultDouble += glm::length(glm::diskRand(2.0));
}
Error += ResultFloat < 200000.f ? 0 : 1;
Error += ResultDouble < 200000.0 ? 0 : 1;
Error += ResultFloat < float(TestSamples) * 2.f ? 0 : 1;
Error += ResultDouble < double(TestSamples) * 2.0 ? 0 : 1;
assert(!Error);
}
@ -305,14 +307,14 @@ int test_ballRand()
float ResultFloat = 0.0f;
double ResultDouble = 0.0f;
for(std::size_t i = 0; i < 100000; ++i)
for(std::size_t i = 0; i < TestSamples; ++i)
{
ResultFloat += glm::length(glm::ballRand(2.0f));
ResultDouble += glm::length(glm::ballRand(2.0));
}
Error += ResultFloat < 200000.f ? 0 : 1;
Error += ResultDouble < 200000.0 ? 0 : 1;
Error += ResultFloat < float(TestSamples) * 2.f ? 0 : 1;
Error += ResultDouble < double(TestSamples) * 2.0 ? 0 : 1;
assert(!Error);
}