OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
TestQuasiRandom.cpp
Go to the documentation of this file.
1
37#include <gtest/gtest.h>
38#include <algorithm>
39#include <cmath>
40#include <vector>
42
43class QuasiRandomTest : public ::testing::Test {
44protected:
45 void SetUp() override {
46 // Test setup
47 }
48};
49
50TEST_F(QuasiRandomTest, BasicGeneration) {
51 gsl_qrng* q = gsl_qrng_alloc("sobol", 2);
52 EXPECT_NE(q, nullptr);
53
54 double x[2];
55 gsl_qrng_get(q, x);
56
57 // Values should be in [0, 1)
58 EXPECT_GE(x[0], 0.0);
59 EXPECT_LT(x[0], 1.0);
60 EXPECT_GE(x[1], 0.0);
61 EXPECT_LT(x[1], 1.0);
62
64}
65
66TEST_F(QuasiRandomTest, SequenceUniqueness) {
67 gsl_qrng* q = gsl_qrng_alloc("sobol", 1);
68
69 std::vector<double> samples(100);
70 for (size_t i = 0; i < samples.size(); ++i) {
71 double x[1];
72 gsl_qrng_get(q, x);
73 samples[i] = x[0];
74 }
75
76 // Check that values are in [0, 1)
77 for (double val : samples) {
78 EXPECT_GE(val, 0.0);
79 EXPECT_LT(val, 1.0);
80 }
81
82 // Check that sequence is not all zeros
83 bool all_zero = true;
84 for (double val : samples) {
85 if (val != 0.0) {
86 all_zero = false;
87 break;
88 }
89 }
90 EXPECT_FALSE(all_zero);
91
93}
94
95TEST_F(QuasiRandomTest, MultiDimensional) {
96 gsl_qrng* q = gsl_qrng_alloc("sobol", 5);
97
98 double x[5];
99 gsl_qrng_get(q, x);
100
101 // All dimensions should be in [0, 1)
102 for (int i = 0; i < 5; ++i) {
103 EXPECT_GE(x[i], 0.0);
104 EXPECT_LT(x[i], 1.0);
105 }
106
107 gsl_qrng_free(q);
108}
109
110TEST_F(QuasiRandomTest, Reproducibility) {
111 gsl_qrng* q1 = gsl_qrng_alloc("sobol", 2);
112 gsl_qrng* q2 = gsl_qrng_alloc("sobol", 2);
113
114 double x1[2], x2[2];
115
116 // Both should start with same sequence
117 gsl_qrng_get(q1, x1);
118 gsl_qrng_get(q2, x2);
119
120 // Values should be the same (deterministic sequence)
121 EXPECT_DOUBLE_EQ(x1[0], x2[0]);
122 EXPECT_DOUBLE_EQ(x1[1], x2[1]);
123
124 gsl_qrng_free(q1);
125 gsl_qrng_free(q2);
126}
127
129 gsl_qrng* q = gsl_qrng_alloc("sobol", 1);
130
131 // Generate many samples and check coverage
132 const int n_samples = 1000;
133 std::vector<double> samples(n_samples);
134
135 for (int i = 0; i < n_samples; ++i) {
136 double x[1];
137 gsl_qrng_get(q, x);
138 samples[i] = x[0];
139 }
140
141 // Check that we cover a reasonable range
142 double min_val = *std::min_element(samples.begin(), samples.end());
143 double max_val = *std::max_element(samples.begin(), samples.end());
144
145 EXPECT_GE(min_val, 0.0);
146 EXPECT_LT(max_val, 1.0);
147 EXPECT_GT(max_val - min_val, 0.5); // Should cover at least half the range
148
149 gsl_qrng_free(q);
150}
void gsl_qrng_free(gsl_qrng *q)
Definition QuasiRandom.h:86
gsl_qrng * gsl_qrng_alloc(const char *, unsigned int dimension)
Definition QuasiRandom.h:78
void gsl_qrng_get(const gsl_qrng *q, double *x)
Definition QuasiRandom.h:84
TEST_F(QuasiRandomTest, BasicGeneration)
void SetUp() override