mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
randomT_test.cpp
Go to the documentation of this file.
1 /** \file randomT_test.cpp
2  */
3 #include "../../catch2/catch.hpp"
4 
5 #include <Eigen/Dense>
6 
7 #define MX_NO_ERROR_REPORTS
8 
9 #include "../../../include/math/randomT.hpp"
10 
11 /** Verify compilation and basic operation of randomT with std::distributions.
12  * Basic tests include verification that seeding works. Note that there is the very slight
13  * possibility that normal operation could return two consecutive variates with the same value
14  * which would cause some of the below tests to fail. Will probably never happen . . .
15  *
16  * \anchor tests_math_randomT_basic
17  */
18 SCENARIO( "Verify compilation and basic operation of randomT with std::distributions", "[math::randomT]" )
19 {
20  GIVEN("a uniform distribution is desired")
21  {
22  WHEN("two double random numbers from same generator requested")
23  {
25 
26  double r1 = uniDist;
27  double r2 = uniDist;
28 
29  REQUIRE(r1 != r2);
30  }
31 
32  WHEN("two double random numbers requested from different generators with same seed")
33  {
36 
37  uniDist1.seed(10);
38  uniDist2.seed(10);
39  double r1 = uniDist1;
40  double r2 = uniDist2;
41 
42  REQUIRE(r1 == r2);
43  }
44 
45  WHEN("two double random numbers requested from different generators with different seed")
46  {
49 
50  uniDist1.seed(10);
51  uniDist2.seed(11);
52  double r1 = uniDist1;
53  double r2 = uniDist2;
54 
55  REQUIRE(r1 != r2);
56  }
57  }
58 
59  GIVEN("a normal distribution is desired")
60  {
61  WHEN("two double random numbers from same generator requested")
62  {
64 
65  double r1 = normDist;
66  double r2 = normDist;
67 
68  REQUIRE(r1 != r2);
69  }
70 
71  WHEN("two double random numbers requested from different generators with same seed")
72  {
75 
76  normDist1.seed(10);
77  normDist2.seed(10);
78  double r1 = normDist1;
79  double r2 = normDist2;
80 
81  REQUIRE(r1 == r2);
82  }
83 
84  WHEN("two double random numbers requested from different generators with different seed")
85  {
88 
89  normDist1.seed(10);
90  normDist2.seed(11);
91  double r1 = normDist1;
92  double r2 = normDist2;
93 
94  REQUIRE(r1 != r2);
95  }
96  }
97 }
98 
99 /** Verify compilation and basic operation of randomT with the Lapace distribution
100  * Basic tests include verification that seeding works. Note that there is the very slight
101  * possibility that normal operation could return two consecutive variates with the same value
102  * which would cause some of the below tests to fail. Will probably never happen . . .
103  *
104  * \anchor tests_math_randomT_basic_laplace
105  */
106 SCENARIO( "Verify compilation and basic operation of randomT with the Lapace distribution", "[math::laplace_distribution]" )
107 {
108  GIVEN("a laplace distribution is desired")
109  {
110  WHEN("two double random numbers from same generator requested")
111  {
113 
114  double r1 = lapDist;
115  double r2 = lapDist;
116 
117  REQUIRE(r1 != r2);
118  }
119 
120  WHEN("two double random numbers requested from different generators with same seed")
121  {
124 
125  lapDist1.seed(10);
126  lapDist2.seed(10);
127  double r1 = lapDist1;
128  double r2 = lapDist2;
129 
130  REQUIRE(r1 == r2);
131  }
132 
133  WHEN("two double random numbers requested from different generators with different seed")
134  {
137 
138  lapDist1.seed(10);
139  lapDist2.seed(11);
140  double r1 = lapDist1;
141  double r2 = lapDist2;
142 
143  REQUIRE(r1 != r2);
144  }
145  }
146 }
A random number type, which functions like any other arithmetic type.
Definition: randomT.hpp:61
void seed(typename ranengT::result_type seedval)
Set the seed of the random engine.
Definition: randomT.hpp:96
SCENARIO("Verify compilation and basic operation of randomT with std::distributions", "[math::randomT]")