OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
TestRandom.cpp File Reference

Unit tests for random number generation (replacement for gsl_rng) More...

#include <gtest/gtest.h>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include "Utilities/Random.h"
Include dependency graph for TestRandom.cpp:

Go to the source code of this file.

Classes

class  RandomTest
 

Functions

 TEST_F (RandomTest, UniformDistribution)
 
 TEST_F (RandomTest, GaussianDistribution)
 
 TEST_F (RandomTest, SeedReproducibility)
 
 TEST_F (RandomTest, DifferentSeedsDifferentSequences)
 
 TEST_F (RandomTest, GaussianStatistics)
 

Detailed Description

Unit tests for random number generation (replacement for gsl_rng)

This file contains comprehensive unit tests for the GSL-compatible random number generator implementation. The implementation uses std::mt19937_64 (Mersenne Twister) as the underlying engine and provides uniform and Gaussian distributions.

Test:
RandomTest::UniformDistribution Tests uniform random number generation in the range [0, 1). Generates 1000 samples and verifies: (1) all values are within bounds, and (2) the mean is approximately 0.5, confirming uniform distribution properties.
Test:
RandomTest::GaussianDistribution Tests Gaussian (normal) random number generation. Generates 10,000 samples with \(\sigma = 2.0\) and verifies: (1) the mean is approximately zero, and (2) the variance is approximately \(\sigma^2 = 4.0\).
Test:
RandomTest::SeedReproducibility Tests that seeding the RNG with the same value produces identical sequences. Creates two RNG instances with the same seed and verifies that they generate the same sequence of random numbers, ensuring deterministic behavior.
Test:
RandomTest::DifferentSeedsDifferentSequences Tests that different seeds produce different random sequences. Creates two RNG instances with different seeds and verifies that they generate different sequences, confirming proper seed handling.
Test:
RandomTest::GaussianStatistics Tests statistical properties of Gaussian distribution with large sample size (100,000 samples). Verifies that the computed mean and standard deviation match the expected values ( \(\mu = 0\), \(\sigma = 1.0\)) within statistical tolerance.

Definition in file TestRandom.cpp.

Function Documentation

◆ TEST_F() [1/5]

TEST_F ( RandomTest  ,
DifferentSeedsDifferentSequences   
)

Definition at line 111 of file TestRandom.cpp.

References gsl_rng_alloc(), gsl_rng_default, gsl_rng_free(), gsl_rng_uniform(), and gsl_rng::seed().

Here is the call graph for this function:

◆ TEST_F() [2/5]

TEST_F ( RandomTest  ,
GaussianDistribution   
)

Definition at line 73 of file TestRandom.cpp.

References gsl_ran_gaussian().

Here is the call graph for this function:

◆ TEST_F() [3/5]

TEST_F ( RandomTest  ,
GaussianStatistics   
)

Definition at line 134 of file TestRandom.cpp.

References gsl_ran_gaussian().

Here is the call graph for this function:

◆ TEST_F() [4/5]

TEST_F ( RandomTest  ,
SeedReproducibility   
)

Definition at line 93 of file TestRandom.cpp.

References gsl_rng_alloc(), gsl_rng_default, gsl_rng_free(), gsl_rng_uniform(), and gsl_rng::seed().

Here is the call graph for this function:

◆ TEST_F() [5/5]

TEST_F ( RandomTest  ,
UniformDistribution   
)

Definition at line 56 of file TestRandom.cpp.

References gsl_rng_uniform().

Here is the call graph for this function: