test_mersenne_twister_engine.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #define BOOST_TEST_MODULE TestMersenneTwisterEngine
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/random/mersenne_twister_engine.hpp>
  13. #include <boost/compute/container/vector.hpp>
  14. #include "check_macros.hpp"
  15. #include "context_setup.hpp"
  16. BOOST_AUTO_TEST_CASE(generate_uint)
  17. {
  18. using boost::compute::uint_;
  19. boost::compute::mt19937 rng(queue);
  20. boost::compute::vector<uint_> vector(10, context);
  21. rng.generate(vector.begin(), vector.end(), queue);
  22. CHECK_RANGE_EQUAL(
  23. uint_, 10, vector,
  24. (uint_(3499211612),
  25. uint_(581869302),
  26. uint_(3890346734),
  27. uint_(3586334585),
  28. uint_(545404204),
  29. uint_(4161255391),
  30. uint_(3922919429),
  31. uint_(949333985),
  32. uint_(2715962298),
  33. uint_(1323567403))
  34. );
  35. }
  36. BOOST_AUTO_TEST_CASE(discard_uint)
  37. {
  38. using boost::compute::uint_;
  39. boost::compute::mt19937 rng(queue);
  40. boost::compute::vector<uint_> vector(5, context);
  41. rng.discard(5, queue);
  42. rng.generate(vector.begin(), vector.end(), queue);
  43. CHECK_RANGE_EQUAL(
  44. uint_, 5, vector,
  45. (uint_(4161255391),
  46. uint_(3922919429),
  47. uint_(949333985),
  48. uint_(2715962298),
  49. uint_(1323567403))
  50. );
  51. }
  52. BOOST_AUTO_TEST_CASE(copy_ctor)
  53. {
  54. using boost::compute::uint_;
  55. boost::compute::mt19937 rng(queue);
  56. boost::compute::mt19937 rng_copy(rng);
  57. boost::compute::vector<uint_> vector(10, context);
  58. rng_copy.generate(vector.begin(), vector.end(), queue);
  59. CHECK_RANGE_EQUAL(
  60. uint_, 10, vector,
  61. (uint_(3499211612),
  62. uint_(581869302),
  63. uint_(3890346734),
  64. uint_(3586334585),
  65. uint_(545404204),
  66. uint_(4161255391),
  67. uint_(3922919429),
  68. uint_(949333985),
  69. uint_(2715962298),
  70. uint_(1323567403))
  71. );
  72. }
  73. BOOST_AUTO_TEST_CASE(assign_op)
  74. {
  75. using boost::compute::uint_;
  76. boost::compute::mt19937 rng(queue);
  77. boost::compute::mt19937 rng_copy(queue);
  78. boost::compute::vector<uint_> vector(10, context);
  79. rng_copy.discard(5, queue);
  80. rng_copy = rng;
  81. rng_copy.generate(vector.begin(), vector.end(), queue);
  82. CHECK_RANGE_EQUAL(
  83. uint_, 10, vector,
  84. (uint_(3499211612),
  85. uint_(581869302),
  86. uint_(3890346734),
  87. uint_(3586334585),
  88. uint_(545404204),
  89. uint_(4161255391),
  90. uint_(3922919429),
  91. uint_(949333985),
  92. uint_(2715962298),
  93. uint_(1323567403))
  94. );
  95. }
  96. BOOST_AUTO_TEST_SUITE_END()