From 5375fbbc9777c3fe8c6eda18848524ba66cb4f1b Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 1 Jun 2011 11:57:43 +0100 Subject: [PATCH] Added random tests --- test/gtx/gtx_random.cpp | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/gtx/gtx_random.cpp b/test/gtx/gtx_random.cpp index 00ef2614..859faa52 100644 --- a/test/gtx/gtx_random.cpp +++ b/test/gtx/gtx_random.cpp @@ -32,11 +32,67 @@ int test_signedRand1() 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) + { + ResultFloat += glm::length(glm::normalizedRand2()); + ResultDouble += glm::length(glm::normalizedRand2()); + } + + Error += glm::equalEpsilon(ResultFloat, float(Max), 0.0001f); + Error += glm::equalEpsilon(ResultDouble, double(Max), 0.0001); + } + + 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) + { + ResultFloatA += glm::length(glm::normalizedRand3()); + ResultDoubleA += glm::length(glm::normalizedRand3()); + 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)); + } + + Error += glm::equalEpsilon(ResultFloatA, float(Max), 0.0001f) ? 0 : 1; + Error += glm::equalEpsilon(ResultDoubleA, double(Max), 0.0001) ? 0 : 1; + Error += glm::equalEpsilon(ResultFloatB, float(Max * 2), 0.0001f) ? 0 : 1; + Error += glm::equalEpsilon(ResultDoubleB, double(Max * 2), 0.0001) ? 0 : 1; + Error += (ResultFloatC >= float(Max) && ResultFloatC <= float(Max * 3)) ? 0 : 1; + Error += (ResultDoubleC >= double(Max) && ResultDoubleC <= double(Max * 3)) ? 0 : 1; + } + + return Error; +} + int main() { int Error = 0; Error += test_signedRand1(); + Error += test_normalizedRand2(); + Error += test_normalizedRand3(); return Error; }