Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

56 строки
1.1 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include "core.h"
  14. #include "lol/unit.h"
  15. namespace lol
  16. {
  17. LOLUNIT_FIXTURE(RandTest)
  18. {
  19. void SetUp() {}
  20. void TearDown() {}
  21. LOLUNIT_TEST(Int32Bits)
  22. {
  23. int const rolls = 2000;
  24. int bits[32];
  25. memset(bits, 0, sizeof(bits));
  26. for (int i = 0; i < rolls; ++i)
  27. {
  28. uint32_t r = rand<int>();
  29. for (int k = 0; k < 31; k++)
  30. {
  31. bits[k] += r & 1;
  32. r >>= 1;
  33. }
  34. }
  35. for (int k = 0; k < 31; k++)
  36. {
  37. LOLUNIT_SET_CONTEXT(k);
  38. LOLUNIT_ASSERT_GREATER(bits[k], rolls / 3);
  39. LOLUNIT_ASSERT_LESS(bits[k], rolls * 2 / 3);
  40. LOLUNIT_UNSET_CONTEXT(k);
  41. }
  42. }
  43. };
  44. } /* namespace lol */