OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
meta_cc_unit_tests.hpp
1/*
2 * meta_cc_unit_tests.hpp
3 *
4 * Created on: Oct 31, 2015
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_DATA_SRC_UTIL_META_CC_UNIT_TESTS_HPP_
9#define OPENFPM_DATA_SRC_UTIL_META_CC_UNIT_TESTS_HPP_
10
11#include "meta_copy.hpp"
12#include "meta_compare.hpp"
13#include "data_type/aggregate.hpp"
14#include "Point_test.hpp"
15
16BOOST_AUTO_TEST_SUITE( util_test )
17
18BOOST_AUTO_TEST_CASE( meta_copy_compare_test )
19{
20 {
22
23 float f_src = 1.0;
24 float f_dst;
25
27
28 BOOST_REQUIRE_EQUAL(f_src,f_dst);
29
30 bool ret = meta_compare<float>::meta_compare_f(f_src,f_dst);
31
32 BOOST_REQUIRE_EQUAL(ret,true);
33
35
36 f_dst = 2.0;
37 ret = meta_compare<float>::meta_compare_f(f_src,f_dst);
38 BOOST_REQUIRE_EQUAL(ret,false);
39
40 }
41
42 {
44
45 float f_src[2][3] = {{1.0,2.9,4.0},{2.3,4.4,9.0}};
46 float f_dst[2][3];
47
49
50 bool ret = meta_compare<float[2][3]>::meta_compare_f(f_src,f_dst);
51
52 BOOST_REQUIRE_EQUAL(ret,true);
53
55
56 f_dst[1][2] = 5.0;
58 BOOST_REQUIRE_EQUAL(ret,false);
59
60 }
61
62 {
64
67
68 boost::fusion::at_c<0>(agg1.data) = 1.0;
69 boost::fusion::at_c<1>(agg1.data) = 2.0;
70 boost::fusion::at_c<2>(agg1.data)[0] = 3.0;
71 boost::fusion::at_c<2>(agg1.data)[1] = 4.0;
72 boost::fusion::at_c<2>(agg1.data)[2] = 5.0;
73
74 meta_copy<aggregate<float,int,float[3]>>::meta_copy_(agg1,agg2);
75
76 bool ret = meta_compare<aggregate<float,int,float[3]>>::meta_compare_f(agg1,agg2);
77
78 BOOST_REQUIRE_EQUAL(ret,true);
79
81
82 boost::fusion::at_c<2>(agg2.data)[2] = 2.0;
83 ret = meta_compare<aggregate<float,int,float[3]>>::meta_compare_f(agg1,agg2);
84
85 BOOST_REQUIRE_EQUAL(ret,false);
86
87 }
88
89 {
91
92 std::string s_src("Test string");
93 std::string s_dst;
94
96
97 BOOST_REQUIRE_EQUAL(s_src,s_dst);
98
99 bool ret = meta_compare<std::string>::meta_compare_f(s_src,s_dst);
100
101 BOOST_REQUIRE_EQUAL(ret,true);
102
104
105 s_dst = std::string("Test string2");
107 BOOST_REQUIRE_EQUAL(ret,false);
108
109 }
110
111 {
113
114 aggregate<std::string,std::vector<float>,std::map<size_t,std::string>,std::string[3]> a_src;
115
116 // fill the complex aggregates
117 a_src.template get<0>() = std::string("Test string");
118
119 a_src.template get<1>().push_back(5.0);
120 a_src.template get<1>().push_back(15.0);
121 a_src.template get<1>().push_back(45.0);
122 a_src.template get<1>().push_back(7.0);
123
124 a_src.template get<2>()[0] = std::string("Test string 2");
125 a_src.template get<2>()[10] = std::string("Test string 3");
126 a_src.template get<2>()[9] = std::string("Test string 4");
127 a_src.template get<2>()[1] = std::string("Test string 5");
128
129 a_src.template get<3>()[0] = std::string("Last string 9");
130 a_src.template get<3>()[1] = std::string("Last string 10");
131 a_src.template get<3>()[2] = std::string("Last string 11");
132
133 aggregate<std::string,std::vector<float>,std::map<size_t,std::string>,std::string[3]> a_dst;
134
135 meta_copy<aggregate<std::string,std::vector<float>,std::map<size_t,std::string>,std::string[3]>>::meta_copy_(a_src,a_dst);
136
137 bool ret = meta_compare<aggregate<std::string,std::vector<float>,std::map<size_t,std::string>,std::string[3]>>::meta_compare_f(a_src,a_dst);
138
139 BOOST_REQUIRE_EQUAL(ret,true);
140
142
143 a_dst.template get<3>()[1] = std::string("Last string 20");
144 ret = meta_compare<aggregate<std::string,std::vector<float>,std::map<size_t,std::string>,std::string[3]>>::meta_compare_f(a_src,a_dst);
145 BOOST_REQUIRE_EQUAL(ret,false);
146
147 }
148
149
150 {
151
153
154 typedef Point_test<float> p;
155
156 Point_test<float> p_src;
157 Point_test<float> p_dst;
158
159 // fill p_src
160 p_src.template get<p::x>() = 1;
161 p_src.template get<p::y>() = 567;
162 p_src.template get<p::z>() = 341;
163 p_src.template get<p::s>() = 5670;
164 p_src.template get<p::v>()[0] = 921;
165 p_src.template get<p::v>()[1] = 5675;
166 p_src.template get<p::v>()[2] = 117;
167 p_src.template get<p::t>()[0][0] = 1921;
168 p_src.template get<p::t>()[0][1] = 25675;
169 p_src.template get<p::t>()[0][2] = 3117;
170 p_src.template get<p::t>()[1][0] = 4921;
171 p_src.template get<p::t>()[1][1] = 55675;
172 p_src.template get<p::t>()[1][2] = 6117;
173 p_src.template get<p::t>()[2][0] = 7921;
174 p_src.template get<p::t>()[2][1] = 85675;
175 p_src.template get<p::t>()[2][2] = 9117;
176
177 meta_copy<Point_test<float>>::meta_copy_(p_src,p_dst);
178
179 bool ret = meta_compare<Point_test<float>>::meta_compare_f(p_src,p_dst);
180 BOOST_REQUIRE_EQUAL(ret,true);
181
183
184 p_dst.template get<p::t>()[2][2] = 9317;
185 ret = meta_compare<Point_test<float>>::meta_compare_f(p_src,p_dst);
186 BOOST_REQUIRE_EQUAL(ret,false);
187
188 }
189}
190
191
192BOOST_AUTO_TEST_CASE( meta_copy_test_op )
193{
194 {
196
197 float f_src = 1.0;
198 float f_dst = 2.0;
199
201
202 BOOST_REQUIRE_EQUAL(f_dst,3.0);
203
205
206 }
207
208 {
210
211 float f_src[2][3] = {{1.0,2.5,4.0},{2.5,4.5,9.0}};
212 float f_dst[2][3] = {{1.0,2.0,3.0},{1.0,2.0,3.0}};
213
215
216 BOOST_REQUIRE_EQUAL(f_dst[0][0],2.0);
217 BOOST_REQUIRE_EQUAL(f_dst[0][1],4.5);
218 BOOST_REQUIRE_EQUAL(f_dst[0][2],7.0);
219
220 BOOST_REQUIRE_EQUAL(f_dst[1][0],3.5);
221 BOOST_REQUIRE_EQUAL(f_dst[1][1],6.5);
222 BOOST_REQUIRE_EQUAL(f_dst[1][2],12.0);
223
225
226 }
227
228 {
230
233
234 boost::fusion::at_c<0>(agg1.data) = 1.0;
235 boost::fusion::at_c<1>(agg1.data) = 2.0;
236 boost::fusion::at_c<2>(agg1.data)[0] = 3.0;
237 boost::fusion::at_c<2>(agg1.data)[1] = 4.0;
238 boost::fusion::at_c<2>(agg1.data)[2] = 5.0;
239
240 boost::fusion::at_c<0>(agg2.data) = 1.0;
241 boost::fusion::at_c<1>(agg2.data) = 2.0;
242 boost::fusion::at_c<2>(agg2.data)[0] = 3.0;
243 boost::fusion::at_c<2>(agg2.data)[1] = 4.0;
244 boost::fusion::at_c<2>(agg2.data)[2] = 5.0;
245
246 meta_copy_op<add_,aggregate<float,int,float[3]>>::meta_copy_op_(agg1,agg2);
247
248 BOOST_REQUIRE_EQUAL(boost::fusion::at_c<0>(agg2.data),2.0);
249 BOOST_REQUIRE_EQUAL(boost::fusion::at_c<1>(agg2.data),4.0);
250 BOOST_REQUIRE_EQUAL(boost::fusion::at_c<2>(agg2.data)[0],6.0);
251 BOOST_REQUIRE_EQUAL(boost::fusion::at_c<2>(agg2.data)[1],8.0);
252 BOOST_REQUIRE_EQUAL(boost::fusion::at_c<2>(agg2.data)[2],10.0);
253
255
256
257 }
258
259 {
261
262 std::string s_src("Test string");
263 std::string s_dst("Test string2");
264
266
267 BOOST_REQUIRE_EQUAL(s_dst,std::string("Test string2Test string"));
268
270
271 }
272
273
274 {
275
277
278 typedef Point_test<float> p;
279
280 Point_test<float> p_src;
281 Point_test<float> p_dst;
282
283 // fill p_src
284 p_src.template get<p::x>() = 1;
285 p_src.template get<p::y>() = 567;
286 p_src.template get<p::z>() = 341;
287 p_src.template get<p::s>() = 5670;
288 p_src.template get<p::v>()[0] = 921;
289 p_src.template get<p::v>()[1] = 5675;
290 p_src.template get<p::v>()[2] = 117;
291 p_src.template get<p::t>()[0][0] = 1921;
292 p_src.template get<p::t>()[0][1] = 25675;
293 p_src.template get<p::t>()[0][2] = 3117;
294 p_src.template get<p::t>()[1][0] = 4921;
295 p_src.template get<p::t>()[1][1] = 55675;
296 p_src.template get<p::t>()[1][2] = 6117;
297 p_src.template get<p::t>()[2][0] = 7921;
298 p_src.template get<p::t>()[2][1] = 85675;
299 p_src.template get<p::t>()[2][2] = 9117;
300
301 // fill p_dst
302 p_dst.template get<p::x>() = 2;
303 p_dst.template get<p::y>() = 568;
304 p_dst.template get<p::z>() = 342;
305 p_dst.template get<p::s>() = 5671;
306 p_dst.template get<p::v>()[0] = 922;
307 p_dst.template get<p::v>()[1] = 5676;
308 p_dst.template get<p::v>()[2] = 118;
309 p_dst.template get<p::t>()[0][0] = 1922;
310 p_dst.template get<p::t>()[0][1] = 25676;
311 p_dst.template get<p::t>()[0][2] = 3118;
312 p_dst.template get<p::t>()[1][0] = 4922;
313 p_dst.template get<p::t>()[1][1] = 55676;
314 p_dst.template get<p::t>()[1][2] = 6118;
315 p_dst.template get<p::t>()[2][0] = 7922;
316 p_dst.template get<p::t>()[2][1] = 85676;
317 p_dst.template get<p::t>()[2][2] = 9118;
318
319 meta_copy_op<add_,Point_test<float>>::meta_copy_op_(p_src,p_dst);
320
321 BOOST_REQUIRE_EQUAL(p_dst.template get<p::x>(),3);
322 BOOST_REQUIRE_EQUAL(p_dst.template get<p::y>(),1135);
323 BOOST_REQUIRE_EQUAL(p_dst.template get<p::z>(),683);
324 BOOST_REQUIRE_EQUAL(p_dst.template get<p::v>()[0],1843);
325 BOOST_REQUIRE_EQUAL(p_dst.template get<p::v>()[1],11351);
326 BOOST_REQUIRE_EQUAL(p_dst.template get<p::v>()[2],235);
327 BOOST_REQUIRE_EQUAL(p_dst.template get<p::t>()[0][0],3843);
328 BOOST_REQUIRE_EQUAL(p_dst.template get<p::t>()[0][1],51351);
329 BOOST_REQUIRE_EQUAL(p_dst.template get<p::t>()[0][2],6235);
330 BOOST_REQUIRE_EQUAL(p_dst.template get<p::t>()[1][0],9843);
331 BOOST_REQUIRE_EQUAL(p_dst.template get<p::t>()[1][1],111351);
332 BOOST_REQUIRE_EQUAL(p_dst.template get<p::t>()[1][2],12235);
333 BOOST_REQUIRE_EQUAL(p_dst.template get<p::t>()[2][0],15843);
334 BOOST_REQUIRE_EQUAL(p_dst.template get<p::t>()[2][1],171351);
335 BOOST_REQUIRE_EQUAL(p_dst.template get<p::t>()[2][2],18235);
336
338
339 }
340}
341
342BOOST_AUTO_TEST_CASE( meta_copy_d_compare_test )
343{
344 {
346
347 float f_src = 1.0;
348 float f_dst;
349
351
352 BOOST_REQUIRE_EQUAL(f_src,f_dst);
353
355
356 }
357
358 {
360
361 float f_src[2][3] = {{1.0,2.9,4.0},{2.3,4.4,9.0}};
362 float f_dst[2][3];
363
365
366 BOOST_REQUIRE_EQUAL(f_src[0][0],f_dst[0][0]);
367 BOOST_REQUIRE_EQUAL(f_src[0][1],f_dst[0][1]);
368 BOOST_REQUIRE_EQUAL(f_src[0][2],f_dst[0][2]);
369 BOOST_REQUIRE_EQUAL(f_src[1][0],f_dst[1][0]);
370 BOOST_REQUIRE_EQUAL(f_src[1][1],f_dst[1][1]);
371 BOOST_REQUIRE_EQUAL(f_src[1][2],f_dst[1][2]);
372
374
375 }
376
377 {
379
382
383 boost::fusion::at_c<0>(agg1.data) = 1.0;
384 boost::fusion::at_c<1>(agg1.data) = 2.0;
385 boost::fusion::at_c<2>(agg1.data)[0] = 3.0;
386 boost::fusion::at_c<2>(agg1.data)[1] = 4.0;
387 boost::fusion::at_c<2>(agg1.data)[2] = 5.0;
388
390
391 BOOST_REQUIRE_EQUAL(boost::fusion::at_c<0>(agg1.data),boost::fusion::at_c<0>(agg2.data));
392 BOOST_REQUIRE_EQUAL(boost::fusion::at_c<1>(agg1.data),boost::fusion::at_c<1>(agg2.data));
393 BOOST_REQUIRE_EQUAL(boost::fusion::at_c<2>(agg1.data)[0],boost::fusion::at_c<2>(agg2.data)[0]);
394 BOOST_REQUIRE_EQUAL(boost::fusion::at_c<2>(agg1.data)[1],boost::fusion::at_c<2>(agg2.data)[1]);
395 BOOST_REQUIRE_EQUAL(boost::fusion::at_c<2>(agg1.data)[2],boost::fusion::at_c<2>(agg2.data)[2]);
396
398
399 }
400
401 {
403
404 std::string s_src("Test string");
405 std::string s_dst;
406
408
409 BOOST_REQUIRE_EQUAL(s_src,s_dst);
410
412
413 }
414
415 {
417
418 aggregate<std::string,std::vector<float>,std::map<size_t,std::string>,std::string[3]> a_src;
419
420 // fill the complex aggregates
421 a_src.template get<0>() = std::string("Test string");
422
423 a_src.template get<1>().push_back(5.0);
424 a_src.template get<1>().push_back(15.0);
425 a_src.template get<1>().push_back(45.0);
426 a_src.template get<1>().push_back(7.0);
427
428 a_src.template get<2>()[0] = std::string("Test string 2");
429 a_src.template get<2>()[10] = std::string("Test string 3");
430 a_src.template get<2>()[9] = std::string("Test string 4");
431 a_src.template get<2>()[1] = std::string("Test string 5");
432
433 a_src.template get<3>()[0] = std::string("Last string 9");
434 a_src.template get<3>()[1] = std::string("Last string 10");
435 a_src.template get<3>()[2] = std::string("Last string 11");
436
437 aggregate<std::string,std::vector<float>,std::map<size_t,std::string>,std::string[3]> a_dst;
438
439 meta_copy_d<aggregate<std::string,std::vector<float>,std::map<size_t,std::string>,std::string[3]>,
440 aggregate<std::string,std::vector<float>,std::map<size_t,std::string>,std::string[3]>>::meta_copy_d_(a_src,a_dst);
441
442
443 BOOST_REQUIRE_EQUAL(a_src.template get<0>(),a_dst.template get<0>());
444 BOOST_REQUIRE_EQUAL(a_src.template get<1>()[0],a_dst.template get<1>()[0]);
445 BOOST_REQUIRE_EQUAL(a_src.template get<1>()[1],a_dst.template get<1>()[1]);
446 BOOST_REQUIRE_EQUAL(a_src.template get<1>()[2],a_dst.template get<1>()[2]);
447 BOOST_REQUIRE_EQUAL(a_src.template get<1>()[3],a_dst.template get<1>()[3]);
448
449 BOOST_REQUIRE_EQUAL(a_src.template get<2>()[0],a_dst.template get<2>()[0]);
450 BOOST_REQUIRE_EQUAL(a_src.template get<2>()[10],a_dst.template get<2>()[10]);
451 BOOST_REQUIRE_EQUAL(a_src.template get<2>()[9],a_dst.template get<2>()[9]);
452 BOOST_REQUIRE_EQUAL(a_src.template get<2>()[1],a_dst.template get<2>()[1]);
453
454 BOOST_REQUIRE_EQUAL(a_src.template get<3>()[0],a_dst.template get<3>()[0]);
455 BOOST_REQUIRE_EQUAL(a_src.template get<3>()[1],a_dst.template get<3>()[1]);
456 BOOST_REQUIRE_EQUAL(a_src.template get<3>()[2],a_dst.template get<3>()[2]);
457
459
460 }
461
462
463 {
464
466
467 typedef Point_test<float> p;
468
469 Point_test<float> p_src;
470 Point_test<float> p_dst;
471
472 // fill p_src
473 p_src.template get<p::x>() = 1;
474 p_src.template get<p::y>() = 567;
475 p_src.template get<p::z>() = 341;
476 p_src.template get<p::s>() = 5670;
477 p_src.template get<p::v>()[0] = 921;
478 p_src.template get<p::v>()[1] = 5675;
479 p_src.template get<p::v>()[2] = 117;
480 p_src.template get<p::t>()[0][0] = 1921;
481 p_src.template get<p::t>()[0][1] = 25675;
482 p_src.template get<p::t>()[0][2] = 3117;
483 p_src.template get<p::t>()[1][0] = 4921;
484 p_src.template get<p::t>()[1][1] = 55675;
485 p_src.template get<p::t>()[1][2] = 6117;
486 p_src.template get<p::t>()[2][0] = 7921;
487 p_src.template get<p::t>()[2][1] = 85675;
488 p_src.template get<p::t>()[2][2] = 9117;
489
490 meta_copy_d<Point_test<float>,Point_test<float>>::meta_copy_d_(p_src,p_dst);
491
492 BOOST_REQUIRE_EQUAL(p_src.template get<p::x>(),p_dst.template get<p::x>());
493 BOOST_REQUIRE_EQUAL(p_src.template get<p::y>(),p_dst.template get<p::y>());
494 BOOST_REQUIRE_EQUAL(p_src.template get<p::z>(),p_dst.template get<p::z>());
495 BOOST_REQUIRE_EQUAL(p_src.template get<p::s>(),p_dst.template get<p::s>());
496
497 BOOST_REQUIRE_EQUAL(p_src.template get<p::v>()[0],p_dst.template get<p::v>()[0]);
498 BOOST_REQUIRE_EQUAL(p_src.template get<p::v>()[1],p_dst.template get<p::v>()[1]);
499 BOOST_REQUIRE_EQUAL(p_src.template get<p::v>()[2],p_dst.template get<p::v>()[2]);
500
501 BOOST_REQUIRE_EQUAL(p_src.template get<p::t>()[0][0],p_dst.template get<p::t>()[0][0]);
502 BOOST_REQUIRE_EQUAL(p_src.template get<p::t>()[0][1],p_dst.template get<p::t>()[0][1]);
503 BOOST_REQUIRE_EQUAL(p_src.template get<p::t>()[0][2],p_dst.template get<p::t>()[0][2]);
504 BOOST_REQUIRE_EQUAL(p_src.template get<p::t>()[1][0],p_dst.template get<p::t>()[1][0]);
505 BOOST_REQUIRE_EQUAL(p_src.template get<p::t>()[1][1],p_dst.template get<p::t>()[1][1]);
506 BOOST_REQUIRE_EQUAL(p_src.template get<p::t>()[1][2],p_dst.template get<p::t>()[1][2]);
507 BOOST_REQUIRE_EQUAL(p_src.template get<p::t>()[2][0],p_dst.template get<p::t>()[2][0]);
508 BOOST_REQUIRE_EQUAL(p_src.template get<p::t>()[2][1],p_dst.template get<p::t>()[2][1]);
509 BOOST_REQUIRE_EQUAL(p_src.template get<p::t>()[2][2],p_dst.template get<p::t>()[2][2]);
510
512
513 }
514}
515
516BOOST_AUTO_TEST_SUITE_END()
517
518#endif /* OPENFPM_DATA_SRC_UTIL_META_CC_UNIT_TESTS_HPP_ */
Test structure used for several test.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
type data
the data
This class compare general objects.
copy for a source object to a destination
Definition meta_copy.hpp:85
__device__ static __host__ void meta_copy_d_(const Tsrc &src, Tdst &dst)
copy and object from src to dst
Definition meta_copy.hpp:92
This class copy general objects applying an operation.
static void meta_copy_op_(const T &src, T &dst)
Meta-copy applying an operation.
This class copy general objects.
Definition meta_copy.hpp:53
__device__ static __host__ void meta_copy_(const T &src, T &dst)
copy and object from src to dst
Definition meta_copy.hpp:60