All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NonRandomCounter_test.cc
Go to the documentation of this file.
1 /**
2  * @file NonRandomCounter_test.cc
3  * @brief Unit test for `NonRandomCounter` random engine.
4  * @date February 14, 2020
5  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
6  * @see `icarusalg/Utilities/NonRandomCounter.h`
7  */
8 
9 // Boost libraries
10 #define BOOST_TEST_MODULE NonRandomCounterTest
11 #include <boost/test/unit_test.hpp>
12 
13 // ICARUS libraries
15 
16 
17 //------------------------------------------------------------------------------
18 void Test() {
19 
20  constexpr std::size_t N = 1024U;
21  constexpr long seed = 3U;
22 
23  util::NonRandomCounter engine { seed };
24 
25  std::cout << "engine { " << seed << " }: ";
26  engine.showStatus();
27 
28  BOOST_CHECK_EQUAL(engine.name(), "NonRandomCounter");
29 
30  // test that the numbers are growing
31  std::array<double, N> numbers;
32  engine.flatArray(numbers.size(), numbers.data());
33  std::cout << "\nengine.flatArray(" << numbers.size() << ", "
34  << ((void*) numbers.data()) << ") => ";
35  engine.showStatus();
36 
37  for (std::size_t i = 1U; i < N; ++i)
38  BOOST_CHECK_LT(numbers[i - 1U], numbers[i]);
39 
40  // test that the numbers are reproducible
41  engine.setSeed(seed, 0);
42  std::cout << "\nengine.setSeed(" << seed << ") => ";
43  engine.showStatus();
44 
45  for (double const expected: numbers)
46  BOOST_CHECK_EQUAL(engine.flat(), expected); // same math, same result
47  std::cout << "\nengine.flat() x " << numbers.size() << " => ";
48  engine.showStatus();
49 
50  // test the other way to set a seed
51  engine.setSeeds(&seed, 1);
52  std::cout << "\nengine.setSeeds(" << ((void*) &seed) << ", 1) => ";
53  engine.showStatus();
54 
55  for (double const expected: numbers)
56  BOOST_CHECK_EQUAL(engine.flat(), expected); // same math, same result
57  std::cout << "\nengine.flat() x " << numbers.size() << " => ";
58  engine.showStatus();
59 
60 } // Test()
61 
62 
63 //------------------------------------------------------------------------------
64 //--- The tests
65 //---
66 BOOST_AUTO_TEST_CASE( TestCase ) {
67 
68  Test();
69 
70 } // BOOST_AUTO_TEST_CASE( TestCase )
71 
BOOST_AUTO_TEST_CASE(AllTests)
Non-random number engine for profiling purposes.
Fast random engine which returns sequential numbers.
void Test(TFile *pFile=nullptr, bool statChecks=true)
unsigned int seed
process_name largeant stream1 can override from command line with o or output physics producers generator N
BEGIN_PROLOG could also be cout