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 * \brief Tests random-number generators and distributions.
3 */
4#include "../../catch2/catch.hpp"
5
6#include <Eigen/Dense>
7
8#define MX_NO_ERROR_REPORTS
9
11
12/** Verify compilation and basic operation of randomT with std::distributions.
13 *
14 * Basic tests include verification that explicit seeding produces reproducible variates.
15 *
16 */
17/**
18 * \ingroup randomT_unit_tests
19 */
20TEST_CASE( "Verify compilation and basic operation of randomT with std::distributions", "[math::randomT]" )
21{
22 GIVEN( "a uniform distribution is desired" )
23 {
24 WHEN( "two double random numbers from same generator requested" )
25 {
27 uniDist.seed( 0xA11CE001 );
28
29 double r1 = uniDist;
30 double r2 = uniDist;
31
32 REQUIRE( r1 != r2 );
33 }
34
35 WHEN( "two double random numbers requested from different generators with same seed" )
36 {
39
40 uniDist1.seed( 10 );
41 uniDist2.seed( 10 );
42 double r1 = uniDist1;
43 double r2 = uniDist2;
44
45 REQUIRE( r1 == r2 );
46 }
47
48 WHEN( "two double random numbers requested from different generators with different seed" )
49 {
52
53 uniDist1.seed( 10 );
54 uniDist2.seed( 11 );
55 double r1 = uniDist1;
56 double r2 = uniDist2;
57
58 REQUIRE( r1 != r2 );
59 }
60 }
61
62 GIVEN( "a normal distribution is desired" )
63 {
64 WHEN( "two double random numbers from same generator requested" )
65 {
67 normDist.seed( 0xA11CE002 );
68
69 double r1 = normDist;
70 double r2 = normDist;
71
72 REQUIRE( r1 != r2 );
73 }
74
75 WHEN( "two double random numbers requested from different generators with same seed" )
76 {
79
80 normDist1.seed( 10 );
81 normDist2.seed( 10 );
82 double r1 = normDist1;
83 double r2 = normDist2;
84
85 REQUIRE( r1 == r2 );
86 }
87
88 WHEN( "two double random numbers requested from different generators with different seed" )
89 {
92
93 normDist1.seed( 10 );
94 normDist2.seed( 11 );
95 double r1 = normDist1;
96 double r2 = normDist2;
97
98 REQUIRE( r1 != r2 );
99 }
100 }
101}
102
103/** Verify compilation and basic operation of randomT with the Laplace distribution
104 *
105 * Basic tests include verification that explicit seeding produces reproducible variates.
106 *
107 */
108/**
109 * \ingroup randomT_unit_tests
110 */
111TEST_CASE( "Verify compilation and basic operation of randomT with the Laplace distribution",
112 "[math::laplace_distribution]" )
113{
114 GIVEN( "a laplace distribution is desired" )
115 {
116 WHEN( "two double random numbers from same generator requested" )
117 {
119 lapDist.seed( 0xA11CE003 );
120
121 double r1 = lapDist;
122 double r2 = lapDist;
123
124 REQUIRE( r1 != r2 );
125 }
126
127 WHEN( "two double random numbers requested from different generators with same seed" )
128 {
131
132 lapDist1.seed( 10 );
133 lapDist2.seed( 10 );
134 double r1 = lapDist1;
135 double r2 = lapDist2;
136
137 REQUIRE( r1 == r2 );
138 }
139
140 WHEN( "two double random numbers requested from different generators with different seed" )
141 {
144
145 lapDist1.seed( 10 );
146 lapDist2.seed( 11 );
147 double r1 = lapDist1;
148 double r2 = lapDist2;
149
150 REQUIRE( r1 != r2 );
151 }
152 }
153}
A random number type, which functions like any other arithmetic type.
Definition randomT.hpp:59
void seed(typename ranengT::result_type seedval)
Set the seed of the random engine.
Definition randomT.hpp:96
TEST_CASE("Verify compilation and basic operation of randomT with std::distributions", "[math::randomT]")
Defines a random number type.