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