• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
13 #include <string>
14 #include <iostream>
15 
16 #include <boost/format.hpp>
17 
18 #include "haertel.hpp"
19 
20 #define BOOST_TEST_MAIN
21 #include <boost/test/included/unit_test.hpp>
22 
23 template<class Gen, class T>
check_validation(Gen & gen,T value,const std::string & name)24 inline void check_validation(Gen & gen, T value, const std::string & name)
25 {
26   for(int i = 0; i < 100000-1; ++i)
27     gen();
28 
29   typename Gen::result_type actual = gen();
30   BOOST_CHECK_MESSAGE(value == actual,
31       boost::str(boost::format("%s: check value == gen() failed [%d != %d]") %
32                  name % value % actual));
33 }
34 
35 // we have validation after 100000 steps with Haertel's generators
36 template<class Gen, class T>
validate(T value,const std::string & name)37 void validate(T value, const std::string & name)
38 {
39   Gen gen(1234567);
40   check_validation(gen, value, name);
41 }
42 
BOOST_AUTO_TEST_CASE(test_haertel)43 BOOST_AUTO_TEST_CASE(test_haertel)
44 {
45   using namespace Haertel;
46   validate<LCG_Af2>(183269031u, "LCG_Af2");
47   validate<LCG_Die1>(522319944u, "LCG_Die1");
48   validate<LCG_Fis>(-2065162233u, "LCG_Fis");
49   validate<LCG_FM>(581815473u, "LCG_FM");
50   validate<LCG_Hae>(28931709, "LCG_Hae");
51   validate<LCG_VAX>(1508154087u, "LCG_VAX");
52   validate<NLG_Inv2>(6666884, "NLG_Inv2");
53   validate<NLG_Inv4>(1521640076, "NLG_Inv4");
54   validate<NLG_Inv5>(641840839, "NLG_Inv5");
55   static const int acorn7_init[]
56     = { 1234567, 7654321, 246810, 108642, 13579, 97531, 555555 };
57   MRG_Acorn7 acorn7(acorn7_init);
58   check_validation(acorn7, 874294697, "MRG_Acorn7");
59   // This currently fails.  I don't want to touch it until
60   // I trace the source of this generator. --SJW
61   validate<MRG_Fib2>(1234567u, "MRG_Fib2");
62 }
63