OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
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 
16 BOOST_AUTO_TEST_SUITE( util_test )
17 
18 BOOST_AUTO_TEST_CASE( meta_copy_compare_test )
19 {
20  {
22 
23  float f_src = 1.0;
24  float f_dst;
25 
26  meta_copy<float>(f_src,f_dst);
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 
48  meta_copy<float[2][3]>(f_src,f_dst);
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 
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 
95  meta_copy<std::string>(s_src,s_dst);
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]>>(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>>(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 
192 BOOST_AUTO_TEST_SUITE_END()
193 
194 #endif /* OPENFPM_DATA_SRC_UTIL_META_CC_UNIT_TESTS_HPP_ */
This class copy general objects.
This class compare general objects.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Definition: aggregate.hpp:21
Test structure used for several test.
Definition: Point_test.hpp:72