PageRenderTime 36ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcommon/tests/llrand_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 127 lines | 89 code | 12 blank | 26 comment | 7 complexity | e4eec1bc35d584b940d040a2faf22af1 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llrandom_test.cpp
  3. * @author Phoenix
  4. * @date 2007-01-25
  5. *
  6. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "linden_common.h"
  28. #include "../test/lltut.h"
  29. #include "../llrand.h"
  30. namespace tut
  31. {
  32. struct random
  33. {
  34. };
  35. typedef test_group<random> random_t;
  36. typedef random_t::object random_object_t;
  37. tut::random_t tut_random("LLSeedRand");
  38. template<> template<>
  39. void random_object_t::test<1>()
  40. {
  41. F32 number = 0.0f;
  42. for(S32 ii = 0; ii < 100000; ++ii)
  43. {
  44. number = ll_frand();
  45. ensure("frand >= 0", (number >= 0.0f));
  46. ensure("frand < 1", (number < 1.0f));
  47. }
  48. }
  49. template<> template<>
  50. void random_object_t::test<2>()
  51. {
  52. F64 number = 0.0f;
  53. for(S32 ii = 0; ii < 100000; ++ii)
  54. {
  55. number = ll_drand();
  56. ensure("drand >= 0", (number >= 0.0));
  57. ensure("drand < 1", (number < 1.0));
  58. }
  59. }
  60. template<> template<>
  61. void random_object_t::test<3>()
  62. {
  63. F32 number = 0.0f;
  64. for(S32 ii = 0; ii < 100000; ++ii)
  65. {
  66. number = ll_frand(2.0f) - 1.0f;
  67. ensure("frand >= 0", (number >= -1.0f));
  68. ensure("frand < 1", (number <= 1.0f));
  69. }
  70. }
  71. template<> template<>
  72. void random_object_t::test<4>()
  73. {
  74. F32 number = 0.0f;
  75. for(S32 ii = 0; ii < 100000; ++ii)
  76. {
  77. number = ll_frand(-7.0);
  78. ensure("drand <= 0", (number <= 0.0));
  79. ensure("drand > -7", (number > -7.0));
  80. }
  81. }
  82. template<> template<>
  83. void random_object_t::test<5>()
  84. {
  85. F64 number = 0.0f;
  86. for(S32 ii = 0; ii < 100000; ++ii)
  87. {
  88. number = ll_drand(-2.0);
  89. ensure("drand <= 0", (number <= 0.0));
  90. ensure("drand > -2", (number > -2.0));
  91. }
  92. }
  93. template<> template<>
  94. void random_object_t::test<6>()
  95. {
  96. S32 number = 0;
  97. for(S32 ii = 0; ii < 100000; ++ii)
  98. {
  99. number = ll_rand(100);
  100. ensure("rand >= 0", (number >= 0));
  101. ensure("rand < 100", (number < 100));
  102. }
  103. }
  104. template<> template<>
  105. void random_object_t::test<7>()
  106. {
  107. S32 number = 0;
  108. for(S32 ii = 0; ii < 100000; ++ii)
  109. {
  110. number = ll_rand(-127);
  111. ensure("rand <= 0", (number <= 0));
  112. ensure("rand > -127", (number > -127));
  113. }
  114. }
  115. }