gtc_random.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2011-09-19
  5. // Updated : 2011-09-19
  6. // Licence : This source is under MIT licence
  7. // File : test/gtc/random.cpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include <glm/glm.hpp>
  10. #include <glm/gtc/random.hpp>
  11. #include <glm/gtx/epsilon.hpp>
  12. #include <iostream>
  13. int test_linearRand()
  14. {
  15. int Error = 0;
  16. {
  17. float ResultFloat = 0.0f;
  18. double ResultDouble = 0.0f;
  19. for(std::size_t i = 0; i < 100000; ++i)
  20. {
  21. ResultFloat += glm::linearRand(-1.0f, 1.0f);
  22. ResultDouble += glm::linearRand(-1.0, 1.0);
  23. }
  24. Error += glm::equalEpsilon(ResultFloat, 0.0f, 0.0001f);
  25. Error += glm::equalEpsilon(ResultDouble, 0.0, 0.0001);
  26. assert(!Error);
  27. }
  28. return Error;
  29. }
  30. /*
  31. int test_normalizedRand2()
  32. {
  33. int Error = 0;
  34. {
  35. std::size_t Max = 100000;
  36. float ResultFloat = 0.0f;
  37. double ResultDouble = 0.0f;
  38. for(std::size_t i = 0; i < Max; ++i)
  39. {
  40. ResultFloat += glm::length(glm::normalizedRand2(1.0f, 1.0f));
  41. ResultDouble += glm::length(glm::normalizedRand2(1.0f, 1.0f));
  42. }
  43. Error += glm::equalEpsilon(ResultFloat, float(Max), 0.01f) ? 0 : 1;
  44. Error += glm::equalEpsilon(ResultDouble, double(Max), 0.01) ? 0 : 1;
  45. assert(!Error);
  46. }
  47. return Error;
  48. }
  49. int test_normalizedRand3()
  50. {
  51. int Error = 0;
  52. {
  53. std::size_t Max = 100000;
  54. float ResultFloatA = 0.0f;
  55. float ResultFloatB = 0.0f;
  56. float ResultFloatC = 0.0f;
  57. double ResultDoubleA = 0.0f;
  58. double ResultDoubleB = 0.0f;
  59. double ResultDoubleC = 0.0f;
  60. for(std::size_t i = 0; i < Max; ++i)
  61. {
  62. ResultFloatA += glm::length(glm::normalizedRand3(1.0f, 1.0f));
  63. ResultDoubleA += glm::length(glm::normalizedRand3(1.0f, 1.0f));
  64. ResultFloatB += glm::length(glm::normalizedRand3(2.0f, 2.0f));
  65. ResultDoubleB += glm::length(glm::normalizedRand3(2.0, 2.0));
  66. ResultFloatC += glm::length(glm::normalizedRand3(1.0f, 3.0f));
  67. ResultDoubleC += glm::length(glm::normalizedRand3(1.0, 3.0));
  68. }
  69. Error += glm::equalEpsilon(ResultFloatA, float(Max), 100.0f) ? 0 : 1;
  70. Error += glm::equalEpsilon(ResultDoubleA, double(Max), 100.0) ? 0 : 1;
  71. Error += glm::equalEpsilon(ResultFloatB, float(Max * 2), 100.0001f) ? 0 : 1;
  72. Error += glm::equalEpsilon(ResultDoubleB, double(Max * 2), 100.0001) ? 0 : 1;
  73. Error += (ResultFloatC >= float(Max) && ResultFloatC <= float(Max * 3)) ? 0 : 1;
  74. Error += (ResultDoubleC >= double(Max) && ResultDoubleC <= double(Max * 3)) ? 0 : 1;
  75. assert(!Error);
  76. }
  77. return Error;
  78. }
  79. */
  80. int main()
  81. {
  82. int Error = 0;
  83. Error += test_linearRand();
  84. //Error += test_normalizedRand2();
  85. //Error += test_normalizedRand3();
  86. return Error;
  87. }