glm/test/gtc/gtc_random.cpp

102 lines
2.8 KiB
C++
Raw Normal View History

2011-09-18 07:05:09 +00:00
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
2011-09-18 09:45:57 +00:00
// Created : 2011-09-19
// Updated : 2011-09-19
2011-09-18 07:05:09 +00:00
// Licence : This source is under MIT licence
2011-09-18 09:45:57 +00:00
// File : test/gtc/random.cpp
2011-09-18 07:05:09 +00:00
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
2011-09-22 19:25:50 +00:00
#include <glm/gtc/random.hpp>
2011-09-18 07:05:09 +00:00
#include <glm/gtx/epsilon.hpp>
#include <iostream>
int test_linearRand()
2011-09-18 07:05:09 +00:00
{
int Error = 0;
{
float ResultFloat = 0.0f;
double ResultDouble = 0.0f;
for(std::size_t i = 0; i < 100000; ++i)
{
2011-09-22 19:25:50 +00:00
ResultFloat += glm::linearRand(-1.0f, 1.0f);
ResultDouble += glm::linearRand(-1.0, 1.0);
2011-09-18 07:05:09 +00:00
}
Error += glm::equalEpsilon(ResultFloat, 0.0f, 0.0001f);
Error += glm::equalEpsilon(ResultDouble, 0.0, 0.0001);
2011-09-18 12:48:19 +00:00
assert(!Error);
2011-09-18 07:05:09 +00:00
}
return Error;
}
int test_normalizedRand2()
{
int Error = 0;
{
std::size_t Max = 100000;
float ResultFloat = 0.0f;
double ResultDouble = 0.0f;
for(std::size_t i = 0; i < Max; ++i)
{
2011-09-18 09:45:57 +00:00
ResultFloat += glm::length(glm::normalizedRand2(1.0f, 1.0f));
ResultDouble += glm::length(glm::normalizedRand2(1.0f, 1.0f));
2011-09-18 07:05:09 +00:00
}
2011-09-18 12:48:19 +00:00
Error += glm::equalEpsilon(ResultFloat, float(Max), 0.01f) ? 0 : 1;
Error += glm::equalEpsilon(ResultDouble, double(Max), 0.01) ? 0 : 1;
2011-09-18 07:05:09 +00:00
assert(!Error);
}
return Error;
}
int test_normalizedRand3()
{
int Error = 0;
{
std::size_t Max = 100000;
float ResultFloatA = 0.0f;
float ResultFloatB = 0.0f;
float ResultFloatC = 0.0f;
double ResultDoubleA = 0.0f;
double ResultDoubleB = 0.0f;
double ResultDoubleC = 0.0f;
for(std::size_t i = 0; i < Max; ++i)
{
2011-09-18 09:45:57 +00:00
ResultFloatA += glm::length(glm::normalizedRand3(1.0f, 1.0f));
ResultDoubleA += glm::length(glm::normalizedRand3(1.0f, 1.0f));
2011-09-18 07:05:09 +00:00
ResultFloatB += glm::length(glm::normalizedRand3(2.0f, 2.0f));
ResultDoubleB += glm::length(glm::normalizedRand3(2.0, 2.0));
ResultFloatC += glm::length(glm::normalizedRand3(1.0f, 3.0f));
ResultDoubleC += glm::length(glm::normalizedRand3(1.0, 3.0));
}
2011-09-18 12:48:19 +00:00
Error += glm::equalEpsilon(ResultFloatA, float(Max), 100.0f) ? 0 : 1;
Error += glm::equalEpsilon(ResultDoubleA, double(Max), 100.0) ? 0 : 1;
Error += glm::equalEpsilon(ResultFloatB, float(Max * 2), 100.0001f) ? 0 : 1;
Error += glm::equalEpsilon(ResultDoubleB, double(Max * 2), 100.0001) ? 0 : 1;
2011-09-18 07:05:09 +00:00
Error += (ResultFloatC >= float(Max) && ResultFloatC <= float(Max * 3)) ? 0 : 1;
Error += (ResultDoubleC >= double(Max) && ResultDoubleC <= double(Max * 3)) ? 0 : 1;
2011-09-18 12:48:19 +00:00
assert(!Error);
2011-09-18 07:05:09 +00:00
}
return Error;
}
int main()
{
int Error = 0;
Error += test_linearRand();
2011-09-18 07:05:09 +00:00
Error += test_normalizedRand2();
Error += test_normalizedRand3();
return Error;
}