All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
NonRandomCounter_test.cc File Reference

Unit test for NonRandomCounter random engine. More...

#include <boost/test/unit_test.hpp>
#include "icarusalg/Utilities/NonRandomCounter.h"

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   NonRandomCounterTest
 

Functions

void Test ()
 
 BOOST_AUTO_TEST_CASE (TestCase)
 

Detailed Description

Unit test for NonRandomCounter random engine.

Date
February 14, 2020
Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.slac..nosp@m.stan.nosp@m.ford..nosp@m.edu)
See Also
icarusalg/Utilities/NonRandomCounter.h

Definition in file NonRandomCounter_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   NonRandomCounterTest

Definition at line 10 of file NonRandomCounter_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( TestCase  )

Definition at line 66 of file NonRandomCounter_test.cc.

66  {
67 
68  Test();
69 
70 } // BOOST_AUTO_TEST_CASE( TestCase )
void Test(TFile *pFile=nullptr, bool statChecks=true)
void Test ( )

Definition at line 18 of file NonRandomCounter_test.cc.

18  {
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()
Fast random engine which returns sequential numbers.
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