MOOSE - Multiscale Object Oriented Simulation Environment
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
test_normal_dist.cpp
Go to the documentation of this file.
1
/***
2
* Filename: test_normal_dist.cpp
3
*
4
* Description: test script.
5
*
6
* Version: 0.0.1
7
* Created: 2018-08-04
8
9
* Revision: none
10
*
11
* Author: Dilawar Singh <dilawars@ncbs.res.in>
12
* Organization: NCBS Bangalore
13
*
14
* License: GNU GPL2
15
*/
16
17
18
#include <iostream>
19
#include <map>
20
#include <iomanip>
21
22
#include "
Distributions.h
"
23
#include "../utility/testing_macros.hpp"
24
25
26
int
test_normal_dist
( )
27
{
28
29
moose::MOOSE_RANDOM_DEVICE
rd;
30
moose::MOOSE_RNG_DEFAULT_ENGINE
gen;
31
gen.seed( 10 );
32
33
moose::MOOSE_NORMAL_DISTRIBUTION<double>
d(0, 1);
34
35
std::map<int, int> hist{};
36
std::vector<double> dist;
37
for
(
int
n=0; n<100000; ++n)
38
{
39
double
x = d(gen);
40
dist.push_back( x );
41
++hist[ std::round(x) ];
42
}
43
44
for
(
auto
p : hist) {
45
std::cout << std::setw(2)
46
<< p.first <<
' '
<< std::string(p.second/200,
'*'
) <<
'\n'
;
47
}
48
49
ASSERT_DOUBLE_EQ
(
"NORMALDIST"
, hist[-3], 542 );
50
ASSERT_DOUBLE_EQ
(
"NORMALDIST"
, hist[-2], 5987 );
51
ASSERT_DOUBLE_EQ
(
"NORMALDIST"
, hist[-1], 24262 );
52
ASSERT_DOUBLE_EQ
(
"NORMALDIST"
, hist[0], 38236 );
53
ASSERT_DOUBLE_EQ
(
"NORMALDIST"
, hist[1], 24386 );
54
ASSERT_DOUBLE_EQ
(
"NORMALDIST"
, hist[2], 6071 );
55
56
return
0;
57
}
58
59
int
main
(
int
argc,
const
char
*argv[])
60
{
61
test_normal_dist
();
62
return
0;
63
}
moose::normal_distribution
Definition:
NormalDistribution.hpp:143
moose::MOOSE_RNG_DEFAULT_ENGINE
std::mersenne_twister_engine< std::uint_fast32_t, 32, 624, 397, 31, 0x9908b0df, 11, 0xffffffff, 7, 0x9d2c5680, 15, 0xefc60000, 18, 1812433253 > MOOSE_RNG_DEFAULT_ENGINE
Definition:
Definitions.h:42
main
int main(int argc, const char *argv[])
Definition:
test_normal_dist.cpp:59
Distributions.h
ASSERT_DOUBLE_EQ
#define ASSERT_DOUBLE_EQ(token, a, b)
Definition:
testing_macros.hpp:149
moose::MOOSE_RANDOM_DEVICE
std::random_device MOOSE_RANDOM_DEVICE
Definition:
Definitions.h:29
test_normal_dist
int test_normal_dist()
Definition:
test_normal_dist.cpp:26
moose-core
randnum
test_normal_dist.cpp
Generated on Tue Sep 4 2018 09:05:33 for MOOSE - Multiscale Object Oriented Simulation Environment by
1.8.6