JayBeams  0.1
Another project to have fun coding.
ut_tde_result.cpp
Go to the documentation of this file.
3 #include <jb/fftw/tde_result.hpp>
4 
5 #include <array>
6 #include <complex>
7 #include <deque>
8 #include <forward_list>
9 #include <list>
10 #include <vector>
11 
12 #include <boost/test/unit_test.hpp>
13 
14 /**
15  * @test Verify that we can create a 2 dim tde_result
16  */
17 BOOST_AUTO_TEST_CASE(fftw_tde_result_2_dim_usage) {
18  using array_type = jb::fftw::aligned_multi_array<float, 3>;
19  using test_tde_result = jb::fftw::aligned_multi_array<std::size_t, 2>;
20  using tde_result_type = jb::fftw::tde_result<array_type, std::size_t>;
21 
22  // create a tde_result based on array_type
23  bool res = std::is_same<tde_result_type::record_type, test_tde_result>::value;
24  BOOST_CHECK_MESSAGE(
25  res == true, "tde_result<array_type> is not multi array float");
26 
27  // create a test timeseries
28  const int M = 5;
29  const int P = 10;
30  const int Q = 20;
31  array_type a(boost::extents[M][P][Q]);
32 
33  // create a test tde_result
34  tde_result_type tde(a);
35 
36  // check size of tde = M * P
37  BOOST_CHECK_MESSAGE(
38  tde.size() == M * P, "tde has an incorrect size=" << tde.size());
39 
40  // fill tde result ...
41  std::size_t counter = 0;
42  for (int i = 0; i != M; ++i) {
43  for (int j = 0; j != P; ++j) {
44  tde[counter] = counter;
45  counter++;
46  }
47  }
48 
49  // ... now check the values
50  counter = 0;
51  for (int i = 0; i != M; ++i) {
52  for (int j = 0; j != P; ++j) {
53  BOOST_CHECK_MESSAGE(
54  tde[counter] == counter, "tde[" << counter << "] != " << counter);
55  counter++;
56  }
57  }
58 }
59 
60 /**
61  * @test Verify that we can create a 2 dim tde_result with std:complex values
62  */
63 BOOST_AUTO_TEST_CASE(fftw_tde_result_2_dim_complex_usage) {
65  using test_tde_result = jb::fftw::aligned_multi_array<std::size_t, 2>;
66  using tde_result_type = jb::fftw::tde_result<array_type, std::size_t>;
67 
68  // create a tde_result based on array_type
69  bool res = std::is_same<tde_result_type::record_type, test_tde_result>::value;
70  BOOST_CHECK_MESSAGE(
71  res == true, "tde_result<array_type> is not multi array float");
72 
73  // create a test timeseries
74  const int M = 5;
75  const int P = 10;
76  const int Q = 20;
77  array_type a(boost::extents[M][P][Q]);
78 
79  // create a test tde_result
80  tde_result_type tde(a);
81 
82  // check size of tde = M * P
83  BOOST_CHECK_MESSAGE(
84  tde.size() == M * P, "tde has an incorrect size=" << tde.size());
85 
86  // fill tde result ...
87  std::size_t counter = 0;
88  for (int i = 0; i != M; ++i) {
89  for (int j = 0; j != P; ++j) {
90  tde[counter] = counter;
91  counter++;
92  }
93  }
94 
95  // ... now check the values
96  counter = 0;
97  for (int i = 0; i != M; ++i) {
98  for (int j = 0; j != P; ++j) {
99  BOOST_CHECK_MESSAGE(
100  tde[counter] == counter, "tde[" << counter << "] != " << counter);
101  counter++;
102  }
103  }
104 }
105 
106 /**
107  * @test Verify that we can create a 2 dim tde_result with std:complex values
108  * with std::complex result value
109  */
110 BOOST_AUTO_TEST_CASE(fftw_tde_result_2_dim_complex_double_usage) {
111  using value_type = std::complex<double>;
113  using test_tde_result = jb::fftw::aligned_multi_array<value_type, 2>;
114  using tde_result_type = jb::fftw::tde_result<array_type, value_type>;
115 
116  // create a tde_result based on array_type
117  bool res = std::is_same<tde_result_type::record_type, test_tde_result>::value;
118  BOOST_CHECK_MESSAGE(
119  res == true, "tde_result<array_type> is not multi array complex type");
120 
121  // create a test timeseries
122  const int M = 5;
123  const int P = 10;
124  const int Q = 20;
125  array_type a(boost::extents[M][P][Q]);
126 
127  // create a test tde_result
128  tde_result_type tde(a);
129 
130  // check size of tde = M * P
131  BOOST_CHECK_MESSAGE(
132  tde.size() == M * P, "tde has an incorrect size=" << tde.size());
133 
134  // fill tde result ...
135  std::size_t counter = 0;
136  for (int i = 0; i != M; ++i) {
137  for (int j = 0; j != P; ++j) {
138  tde[counter] = value_type(counter, counter);
139  counter++;
140  }
141  }
142 
143  // ... now check the values
144  counter = 0;
145  for (int i = 0; i != M; ++i) {
146  for (int j = 0; j != P; ++j) {
147  BOOST_CHECK_MESSAGE(
148  tde[counter] == value_type(counter, counter),
149  "tde[" << counter << "] != " << counter);
150  counter++;
151  }
152  }
153 }
154 
155 /**
156  * @test Verify that we can create a 1 dim tde_result based on an
157  * aligned_multi_array container.
158  */
159 BOOST_AUTO_TEST_CASE(fftw_tde_result_1_dim_usage) {
160  using array_type = jb::fftw::aligned_multi_array<float, 2>;
161  using test_tde_result = jb::fftw::aligned_multi_array<std::size_t, 1>;
162  using tde_result_type = jb::fftw::tde_result<array_type, std::size_t>;
163 
164  // create a tde_result based on array_type
165  bool res = std::is_same<tde_result_type::record_type, test_tde_result>::value;
166  BOOST_CHECK_MESSAGE(
167  res == true, "tde_result<array_type> is not multi array float");
168 
169  // create a test timeseries
170  const int M = 50;
171  const int P = 100;
172  array_type a(boost::extents[M][P]);
173 
174  // create a test tde_result
175  tde_result_type tde(a);
176 
177  // check size of tde = M
178  BOOST_CHECK_MESSAGE(
179  tde.size() == M, "tde has an incorrect size=" << tde.size());
180 
181  // fill tde result ...
182  std::size_t counter = 0;
183  for (int i = 0; i != M; ++i) {
184  tde[counter] = counter;
185  counter++;
186  }
187 
188  // ... now check the values
189  counter = 0;
190  for (int i = 0; i != M; ++i) {
191  BOOST_CHECK_MESSAGE(
192  tde[counter] == counter, "tde[" << counter << "] != " << counter);
193  counter++;
194  }
195 }
196 
197 /**
198  * @test Verify that we can create a 0 dim tde_result based on a
199  * aligned multi array container.
200  */
201 BOOST_AUTO_TEST_CASE(fftw_tde_result_0_dim_multi_array_usage) {
202  using array_type = jb::fftw::aligned_multi_array<float, 1>;
203  using test_tde_result = std::size_t;
204  using tde_result_type = jb::fftw::tde_result<array_type, std::size_t>;
205 
206  // create a tde_result based on array_type
207  bool res = std::is_same<tde_result_type::record_type, test_tde_result>::value;
208  BOOST_CHECK_MESSAGE(res == true, "tde_result<array_type> is not std:size_t");
209 
210  // create a test timeseries
211  const int M = 1000;
212  array_type a(boost::extents[M]);
213 
214  // create a test tde_result
215  tde_result_type tde(a);
216 
217  // check size of tde = q
218  BOOST_CHECK_MESSAGE(
219  tde.size() == 1, "tde has an incorrect size=" << tde.size());
220 
221  // fill tde result ...
222  tde[0] = 10;
223 
224  // ... now check the values
225  BOOST_CHECK_MESSAGE(tde[0] == 10, "tde[0] != 10");
226 }
227 
228 /**
229  * @test Verify that we can create a 0 dim tde_result based on a array
230  * container.
231  */
232 BOOST_AUTO_TEST_CASE(fftw_tde_result_0_dim_array_usage) {
233  const int M = 1000;
234  using array_type = std::array<float, M>;
235  using test_tde_result = std::size_t;
236  using tde_result_type = jb::fftw::tde_result<array_type, std::size_t>;
237 
238  // create a tde_result based on array_type
239  bool res = std::is_same<tde_result_type::record_type, test_tde_result>::value;
240  BOOST_CHECK_MESSAGE(res == true, "tde_result<array_type> is not std:size_t");
241 
242  // create a test timeseries
243  array_type a;
244 
245  // create a test tde_result
246  tde_result_type tde(a);
247 
248  // check size of tde = 1
249  BOOST_CHECK_MESSAGE(
250  tde.size() == 1, "tde has an incorrect size=" << tde.size());
251 
252  // fill tde result ...
253  tde[0] = 10;
254 
255  // ... now check the values
256  BOOST_CHECK_MESSAGE(tde[0] == 10, "tde[0] != 10");
257 }
258 
259 /**
260  * @test Verify that we can create a 0 dim tde_result based on a vector
261  * container.
262  */
263 BOOST_AUTO_TEST_CASE(fftw_tde_result_0_dim_vector_usage) {
264  using array_type = std::vector<float>;
265  using test_tde_result = std::size_t;
266  using tde_result_type = jb::fftw::tde_result<array_type, std::size_t>;
267 
268  // create a tde_result based on array_type
269  bool res = std::is_same<tde_result_type::record_type, test_tde_result>::value;
270  BOOST_CHECK_MESSAGE(res == true, "tde_result<array_type> is not std:size_t");
271 
272  // create a test timeseries
273  const int M = 1000;
274  array_type a(M);
275 
276  // create a test tde_result
277  tde_result_type tde(a);
278 
279  // check size of tde = 1
280  BOOST_CHECK_MESSAGE(
281  tde.size() == 1, "tde has an incorrect size=" << tde.size());
282 
283  // fill tde result ...
284  tde[0] = 10;
285 
286  // ... now check the values
287  BOOST_CHECK_MESSAGE(tde[0] == 10, "tde[0] != 10");
288 }
289 
290 /**
291  * @test Verify that we can create a 0 dim tde_result based on a deque
292  * container.
293  */
294 BOOST_AUTO_TEST_CASE(fftw_tde_result_0_dim_deque_usage) {
295  using array_type = std::deque<float>;
296  using test_tde_result = std::size_t;
297  using tde_result_type = jb::fftw::tde_result<array_type, std::size_t>;
298 
299  // create a tde_result based on array_type
300  bool res = std::is_same<tde_result_type::record_type, test_tde_result>::value;
301  BOOST_CHECK_MESSAGE(res == true, "tde_result<array_type> is not std:size_t");
302 
303  // create a test timeseries
304  const int M = 1000;
305  array_type a(M);
306 
307  // create a test tde_result
308  tde_result_type tde(a);
309 
310  // check size of tde = 1
311  BOOST_CHECK_MESSAGE(
312  tde.size() == 1, "tde has an incorrect size=" << tde.size());
313 
314  // fill tde result ...
315  tde[0] = 10;
316 
317  // ... now check the values
318  BOOST_CHECK_MESSAGE(tde[0] == 10, "tde[0] != 10");
319 }
320 
321 /**
322  * @test Verify that we can create a 0 dim tde_result based on a
323  * forward_list container.
324  */
325 BOOST_AUTO_TEST_CASE(fftw_tde_result_0_dim_forward_list_usage) {
326  using array_type = std::forward_list<float>;
327  using test_tde_result = std::size_t;
328  using tde_result_type = jb::fftw::tde_result<array_type, std::size_t>;
329 
330  // create a tde_result based on array_type
331  bool res = std::is_same<tde_result_type::record_type, test_tde_result>::value;
332  BOOST_CHECK_MESSAGE(res == true, "tde_result<array_type> is not std:size_t");
333 
334  // create a test timeseries
335  const int M = 1000;
336  array_type a(M);
337 
338  // create a test tde_result
339  tde_result_type tde(a);
340 
341  // check size of tde = 1
342  BOOST_CHECK_MESSAGE(
343  tde.size() == 1, "tde has an incorrect size=" << tde.size());
344 
345  // fill tde result ...
346  tde[0] = 10;
347 
348  // ... now check the values
349  BOOST_CHECK_MESSAGE(tde[0] == 10, "tde[0] != 10");
350 }
351 
352 /**
353  * @test Verify that we can create a 0 dim tde_result based on a list container.
354  */
355 BOOST_AUTO_TEST_CASE(fftw_tde_result_0_dim_list_usage) {
356  using array_type = std::list<float>;
357  using test_tde_result = std::size_t;
358  using tde_result_type = jb::fftw::tde_result<array_type, std::size_t>;
359 
360  // create a tde_result based on array_type
361  bool res = std::is_same<tde_result_type::record_type, test_tde_result>::value;
362  BOOST_CHECK_MESSAGE(res == true, "tde_result<array_type> is not std:size_t");
363 
364  // create a test timeseries
365  const int M = 1000;
366  array_type a(M);
367 
368  // create a test tde_result
369  tde_result_type tde(a);
370 
371  // check size of tde = 1
372  BOOST_CHECK_MESSAGE(
373  tde.size() == 1, "tde has an incorrect size=" << tde.size());
374 
375  // fill tde result ...
376  tde[0] = 10;
377 
378  // ... now check the values
379  BOOST_CHECK_MESSAGE(tde[0] == 10, "tde[0] != 10");
380 }
A time-delay estimator (TDE) is an algorithm to compare two families of timeseries and return the est...
Definition: tde_result.hpp:37
boost::multi_array< value_type, num_dims, jb::fftw::allocator< value_type > > aligned_multi_array
Alias boost::multi_array with properly allocated storage for FFTW3.
BOOST_AUTO_TEST_CASE(fftw_tde_result_2_dim_usage)