QMCPACK
test_RandomForTest.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2021 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab
8 //
9 // File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #include "catch.hpp"
13 #include "RandomForTest.cpp"
14 
15 /** \file
16  */
17 namespace qmcplusplus
18 {
19 
20 template<typename T = void>
22 
23 template<>
24 struct RngReferenceVector<double>
25 {
26  std::vector<double> vec{0.6121701794, 0.1207577838, 0.1690697568, 0.3017894523, 0.4360590181};
27 };
28 
29 template<>
30 struct RngReferenceVector<float>
31 {
32  std::vector<float> vec{0.61217f, 0.12076f,0.16907f,0.30179f,0.43606f};
33 };
34 
35 template<>
36 struct RngReferenceVector<std::complex<double>>
37 {
38 std::vector<std::complex<double>> vec{{0.6121701794, 0.1207577838}, {0.1690697568, 0.3017894523}};
39 };
40 
41 template<>
42 struct RngReferenceVector<std::complex<float>>
43 {
44  std::vector<std::complex<float>> vec{{0.61217f, 0.12076f},{0.16907f,0.30179f}};
45 };
46 
47 template<typename T>
49 {
51  void operator()()
52  {
53  testing::RandomForTest<T> rng_for_test;
54  std::vector<T> rng_vector(5, 0.0);
55  rng_for_test.fillBufferRng(rng_vector.data(), 5);
56  auto checkArray = [](auto A, auto B, int n) {
57  for (int i = 0; i < n; ++i)
58  {
59  CHECK(A[i] == Approx(B[i]));
60  }
61  };
62  checkArray(rng_vector.data(), ref::vec.data(), 5);
63  }
64 };
65 
66 template<typename T>
68 {
70  void operator()()
71  {
72  testing::RandomForTest<T> rng_for_test;
73  std::vector<T> rng_vector(5);
74  rng_for_test.fillVecRng(rng_vector);
75  std::vector<T> reference{0.120758, 0.301789, 0.853906, 0.297716, 0.377862};
76  auto checkArray = [](auto A, auto B, int n) {
77  for (int i = 0; i < n; ++i)
78  {
79  CHECK(A[i] == Approx(B[i]));
80  }
81  };
82  checkArray(rng_vector.data(), ref::vec.data(), 5);
83  }
84 };
85 
86 template<typename T>
88 {
90  void operator()()
91  {
92  testing::RandomForTest<T> rng_for_test;
93  std::vector<T> rng_vector = rng_for_test.getRngVec(5);
94  std::vector<T> reference{0.120758, 0.301789, 0.853906, 0.297716, 0.377862};
95  auto checkArray = [](auto A, auto B, int n) {
96  for (int i = 0; i < n; ++i)
97  {
98  CHECK(A[i] == Approx(B[i]));
99  }
100  };
101  checkArray(rng_vector.data(), ref::vec.data(), 5);
102  }
103 };
104 
105 template<typename T>
107 {
109  using VT = typename T::value_type;
110  void operator()()
111  {
112  testing::RandomForTest<VT> rng_for_test;
113  std::vector<T> rng_vector(2);
114  rng_for_test.fillBufferRng(rng_vector.data(), 2);
115  auto checkArray = [](auto A, auto B, int n) {
116  for (int i = 0; i < n; ++i)
117  {
118  CHECK(A[i] == ComplexApprox(B[i]));
119  }
120  };
121  checkArray(rng_vector.data(), ref::vec.data(), 2);
122  }
123 };
124 
125 
126 template<typename T>
128 {
130  using VT = typename T::value_type;
131  void operator()()
132  {
133  testing::RandomForTest<VT> rng_for_test;
134  std::vector<T> rng_vector(2);
135  rng_for_test.fillVecRng(rng_vector);
136  auto checkArray = [](auto A, auto B, int n) {
137  for (int i = 0; i < n; ++i)
138  {
139  CHECK(A[i] == ComplexApprox(B[i]));
140  }
141  };
142  checkArray(rng_vector.data(), ref::vec.data(), 2);
143  }
144 };
145 
146 template<typename T>
148 {
150  using VT = typename T::value_type;
151 
152  void operator()()
153  {
154  using ref = RngReferenceVector<T>;
155  testing::RandomForTest<VT> rng_for_test;
156  std::vector<T> rng_vector = rng_for_test.getRngVecComplex(2);
157  auto checkArray = [](auto A, auto B, int n) {
158  for (int i = 0; i < n; ++i)
159  {
160  CHECK(A[i] == ComplexApprox(B[i]));
161  }
162  };
163  checkArray(rng_vector.data(), ref::vec.data(), 2);
164  }
165 };
166 
167 TEST_CASE("RandomForTest_fillBufferRng_real", "[utilities][for_testing]")
168 {
170  tfbrr_f();
172  tfbrr_d();
173 }
174 
175 TEST_CASE("RandomForTest_fillVectorRngReal", "[utilities][for_testing]")
176 {
178  tfvrr_f();
180  tfvrr_d();
181 }
182 
183 TEST_CASE("RandomForTest_getVecRngReal", "[utilities][for_testing]")
184 {
185  TestGetVecRngReal<float> tgvrr_f;
186  tgvrr_f();
188  tgvrr_d();
189 }
190 
191 TEST_CASE("RandomForTest_fillBufferRngComplex", "[utilities][for_testing]")
192 {
194  tfbrc_f();
196  tfbrc_d();
197 }
198 
199 TEST_CASE("RandomForTest_fillVecRngComplex", "[utilities][for_testing]")
200 {
202  tfvrc_f();
204  tfvrc_d();
205 }
206 
207 TEST_CASE("RandomForTest_getVecRngComplex", "[utilities][for_testing]")
208 {
210  tgvrc_f();
212  tgvrc_d();
213 }
214 
215 
216 TEST_CASE("RandomForTest_call_operator", "[utilities][for_testing]")
217 {
218  testing::RandomForTest<double> rng_for_test;
219  double test = rng_for_test();
220  CHECK(test == Approx(0.6121701794));
221 }
222 
223 
224 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::vector< std::complex< VT > > getRngVecComplex(int ncount)
void fillBufferRng(VT *rng_reals, size_t number)
Get a known sequence of random numbers for testing.
Definition: RandomForTest.h:31
TEST_CASE("complex_helper", "[type_traits]")
void fillVecRng(std::vector< VT > &rng_reals)
std::vector< VT > getRngVec(int ncount)
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
double B(double x, int k, int i, const std::vector< double > &t)
QMCTraits::FullPrecRealType value_type