RandomNumbersUnitTest.cpp File Reference
#include <iostream>
#include "DPMBase.h"
#include "Mercury2D.h"
#include "Math/ExtendedMath.h"

Classes

class  my_problem
 todo{This code is not working as is wanted} More...
 
class  my_problem_HGRID
 todo{This code is not working as is wanted} More...
 

Functions

int main (int argc UNUSED, char *argv[] UNUSED)
 

Function Documentation

◆ main()

int main ( int argc  UNUSED,
char *argv[]  UNUSED 
)

Start off my solving the default problem

104 {
105  logger(INFO, "First test the gamma function is working\n"
106  "---------------------------------------- \n\n"
107  "Gamma(4) = % : Error %\n"
108  "Gamma(3.5) = % : Error %",
110  mathsFunc::gamma(3.5) - 3.323);
111 
112  logger(INFO, "Second test the chi-squared distribution is working\n"
113  "---------------------------------------------------\n\n"
114  "\nFirst test chi(1.07,1) = % Error %\n"
115  "First test chi(1.07,1) = % Error %\n"
116  "First test chi(1.07,1) = % Error %",
120  helpers::check(mathsFunc::chi_squared_prob(1.07, 1) - 0.3, 0.0250886, 1e-6, "Checking quality of chi-squared test");
121 
123  my_problem problem;
124 
126 
127  logger(INFO, "\nSecond test the actually random number generate : Linear Congruential Generator\n"
128  "----------------------------------------------\n\n"
129  "First with the default parameters, prob numbers are from uniform = ", Flusher::NO_FLUSH);
130  helpers::check(problem.random.test(), 0.467846, 1e-6, "Checking test result");
131 
132  problem.random.setLinearCongruentialGeneratorParmeters(65539, 0, mathsFunc::cubic(1024) * 2 - 1);
133  logger(INFO, "Third test, now with Stefans' the default parameters, prob numbers are from uniform = ",
135  helpers::check(problem.random.test(), 0.131117, 1e-6, "Checking test result");
136 
138  problem.random.setLinearCongruentialGeneratorParmeters(1103515245, 12345, 1024 * 1024 * 1024);
139  problem.random.setRandomSeed(0);
140 
141  logger(INFO, "\nForth test the actually random number generate : Lagged Fibonacci Generator\n"
142  "----------------------------------------------\n"
143  "First with the default parameters, prob numbers are from uniform = ", Flusher::NO_FLUSH);
144  helpers::check(problem.random.test(), 0.617585, 1e-6, "Checking test result");
145 }
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ LAGGED_FIBONACCI_GENERATOR
@ LINEAR_CONGRUENTIAL_GENERATOR
RNG random
This is a random generator, often used for setting up the initial conditions etc.....
Definition: DPMBase.h:1432
void setRandomSeed(unsigned long int new_seed)
This is the seed for the random number generator (note the call to seed_LFG is only required really i...
Definition: RNG.cc:53
void setLinearCongruentialGeneratorParmeters(const unsigned int a, const unsigned int c, unsigned int m)
This functions set the parameters for the LCG random number generator. It goes multiplier,...
Definition: RNG.cc:91
Mdouble test()
This function tests the quality of random numbers, based on the chi-squared test.
Definition: RNG.cc:289
void setRandomNumberGenerator(RNGType type)
Allows the user to set which random number generator is used.
Definition: RNG.cc:138
todo{This code is not working as is wanted}
Definition: elastic_gas.cpp:34
void check(double real, double ideal, double error, std::string errorMessage)
Definition: TestHelpers.cc:37
Mdouble gamma(Mdouble gamma_in)
This is the gamma function returns the true value for the half integer value.
Definition: ExtendedMath.cc:137
Mdouble chi_squared_prob(Mdouble x, unsigned int k)
This is the function which actually gives the probability back using a chi squared test.
Definition: ExtendedMath.cc:188
T cubic(const T val)
calculates the cube of a number
Definition: ExtendedMath.h:115

References helpers::check(), mathsFunc::chi_squared_prob(), mathsFunc::cubic(), mathsFunc::gamma(), INFO, LAGGED_FIBONACCI_GENERATOR, LINEAR_CONGRUENTIAL_GENERATOR, logger, NO_FLUSH, DPMBase::random, RNG::setLinearCongruentialGeneratorParmeters(), RNG::setRandomNumberGenerator(), RNG::setRandomSeed(), and RNG::test().