test_haertel.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* haertel.hpp file
  2. *
  3. * Copyright Jens Maurer 2000, 2002
  4. * Distributed under the Boost Software License, Version 1.0. (See
  5. * accompanying file LICENSE_1_0.txt or copy at
  6. * http://www.boost.org/LICENSE_1_0.txt)
  7. *
  8. * $Id$
  9. *
  10. * Revision history
  11. */
  12. #include <string>
  13. #include <iostream>
  14. #include <boost/format.hpp>
  15. #include "haertel.hpp"
  16. #define BOOST_TEST_MAIN
  17. #include <boost/test/included/unit_test.hpp>
  18. template<class Gen, class T>
  19. inline void check_validation(Gen & gen, T value, const std::string & name)
  20. {
  21. for(int i = 0; i < 100000-1; ++i)
  22. gen();
  23. typename Gen::result_type actual = gen();
  24. BOOST_CHECK_MESSAGE(value == actual,
  25. boost::str(boost::format("%s: check value == gen() failed [%d != %d]") %
  26. name % value % actual));
  27. }
  28. // we have validation after 100000 steps with Haertel's generators
  29. template<class Gen, class T>
  30. void validate(T value, const std::string & name)
  31. {
  32. Gen gen(1234567);
  33. check_validation(gen, value, name);
  34. }
  35. BOOST_AUTO_TEST_CASE(test_haertel)
  36. {
  37. using namespace Haertel;
  38. validate<LCG_Af2>(183269031u, "LCG_Af2");
  39. validate<LCG_Die1>(522319944u, "LCG_Die1");
  40. validate<LCG_Fis>(-2065162233u, "LCG_Fis");
  41. validate<LCG_FM>(581815473u, "LCG_FM");
  42. validate<LCG_Hae>(28931709, "LCG_Hae");
  43. validate<LCG_VAX>(1508154087u, "LCG_VAX");
  44. validate<NLG_Inv2>(6666884, "NLG_Inv2");
  45. validate<NLG_Inv4>(1521640076, "NLG_Inv4");
  46. validate<NLG_Inv5>(641840839, "NLG_Inv5");
  47. static const int acorn7_init[]
  48. = { 1234567, 7654321, 246810, 108642, 13579, 97531, 555555 };
  49. MRG_Acorn7 acorn7(acorn7_init);
  50. check_validation(acorn7, 874294697, "MRG_Acorn7");
  51. // This currently fails. I don't want to touch it until
  52. // I trace the source of this generator. --SJW
  53. validate<MRG_Fib2>(1234567u, "MRG_Fib2");
  54. }