1 #ifndef GRID_UNIT_TEST_HPP
2 #define GRID_UNIT_TEST_HPP
5 #include "map_grid.hpp"
6 #include "Point_test.hpp"
7 #include "Space/Shape/HyperCube.hpp"
9 #include "grid_util_test.hpp"
11 #ifdef TEST_COVERAGE_MODE
17 template<
unsigned int dim,
typename g>
void test_layout_gridNd(g & c3,
size_t sz);
18 template<
unsigned int dim,
typename g>
void test_layout_gridObjNd(g & c3,
size_t sz);
19 template<
typename g>
void test_layout_grid3d(g & c3,
size_t sz);
27 template<
unsigned int dim>
void test_all_grid(
size_t sz)
31 for (
size_t i = 0 ; i < dim ; i++)
36 test_layout_gridNd<dim>(c3,sz);}
40 test_layout_gridObjNd<dim>(c3,sz);}
45 c3.template setMemory();
46 test_layout_gridNd<dim>(c3,sz);}
49 c3.template setMemory();
50 test_layout_gridObjNd<dim>(c3,sz);}
56 test_layout_gridObjNd<dim>(c3,sz);}
60 test_layout_gridNd<dim>(c3,sz);}
66 test_layout_gridNd<dim>(c3,sz);}
70 test_layout_gridObjNd<dim>(c3,sz);}
77 template<
typename g>
void test_layout_grid3d(g & c3,
size_t sz)
81 std::cout <<
"3D Array with grid_key (without redundant dimension): " <<
"\n";
92 for (
size_t i = 0 ; i < sz ; i++)
94 for (
size_t j = 0 ; j < sz ; j++)
96 for (
size_t k = 0 ; k < sz ; k++)
101 c3.template get<P::x>(kk) = 1.1f;
102 c3.template get<P::y>(kk) = 1.2f;
103 c3.template get<P::z>(kk) = 1.3f;
104 c3.template get<P::s>(kk) = 1.0f;
106 c3.template get<P::v>(kk)[0] = 1.0f;
107 c3.template get<P::v>(kk)[1] = 2.0f;
108 c3.template get<P::v>(kk)[2] = 3.0f;
110 c3.template get<P::t>(kk)[0][0] = 1.0f;
111 c3.template get<P::t>(kk)[0][1] = 2.0f;
112 c3.template get<P::t>(kk)[0][2] = 3.0f;
113 c3.template get<P::t>(kk)[1][0] = 4.0f;
114 c3.template get<P::t>(kk)[1][1] = 5.0f;
115 c3.template get<P::t>(kk)[1][2] = 6.0f;
116 c3.template get<P::t>(kk)[2][0] = 7.0f;
117 c3.template get<P::t>(kk)[2][1] = 8.0f;
118 c3.template get<P::t>(kk)[2][2] = 9.0f;
129 std::cout <<
"End : " << sz*sz*sz*16*4 <<
" Byte " <<
" Bandwidth: " << sz*sz*sz*16*4/1024/1024/t.
getwct() <<
" MB/s ";
136 for (
size_t i = 0 ; i < sz ; i++)
138 for (
size_t j = 0 ; j < sz ; j++)
140 for (
size_t k = 0 ; k < sz ; k++)
144 c3.template get<P::x>(kk) = i;
145 c3.template get<P::y>(kk) = j;
146 c3.template get<P::z>(kk) = k;
147 c3.template get<P::s>(kk) = i+j+k;
149 c3.template get<P::v>(kk)[0] = i;
150 c3.template get<P::v>(kk)[1] = j;
151 c3.template get<P::v>(kk)[2] = k;
153 c3.template get<P::t>(kk)[0][0] = i+i;
154 c3.template get<P::t>(kk)[0][1] = i+j;
155 c3.template get<P::t>(kk)[0][2] = i+k;
156 c3.template get<P::t>(kk)[1][0] = j+i;
157 c3.template get<P::t>(kk)[1][1] = j+j;
158 c3.template get<P::t>(kk)[1][2] = j+k;
159 c3.template get<P::t>(kk)[2][0] = k+i;
160 c3.template get<P::t>(kk)[2][1] = k+j;
161 c3.template get<P::t>(kk)[2][2] = k+k;
166 for (
size_t i = 0 ; i < sz ; i++)
168 for (
size_t j = 0 ; j < sz ; j++)
170 for (
size_t k = 0 ; k < sz ; k++)
174 if (c3.template get<P::x>(kk) != i) passed =
false;
175 if (c3.template get<P::y>(kk) != j) passed =
false;
176 if (c3.template get<P::z>(kk) != k) passed =
false;
177 if (c3.template get<P::s>(kk) != i+j+k) passed =
false;
179 if (c3.template get<P::v>(kk)[0] != i) passed =
false;
180 if (c3.template get<P::v>(kk)[1] != j) passed =
false;
181 if (c3.template get<P::v>(kk)[2] != k) passed =
false;
183 if (c3.template get<P::t>(kk)[0][0] != i+i) passed =
false;
184 if (c3.template get<P::t>(kk)[0][1] != i+j) passed =
false;
185 if (c3.template get<P::t>(kk)[0][2] != i+k) passed =
false;
186 if (c3.template get<P::t>(kk)[1][0] != j+i) passed =
false;
187 if (c3.template get<P::t>(kk)[1][1] != j+j) passed =
false;
188 if (c3.template get<P::t>(kk)[1][2] != j+k) passed =
false;
189 if (c3.template get<P::t>(kk)[2][0] != k+i) passed =
false;
190 if (c3.template get<P::t>(kk)[2][1] != k+j) passed =
false;
191 if (c3.template get<P::t>(kk)[2][2] != k+k) passed =
false;
196 BOOST_REQUIRE_EQUAL(passed,
true);
199 template<
unsigned int dim,
typename g>
void test_layout_gridObjNd(g & c3,
size_t sz)
202 std::cout << dim <<
"D Array with grid_key (without redundant dimension): " <<
"\n";
219 auto v = c3.get_o(kk);
223 v.template get<P::x>() = 1.1f;
224 v.template get<P::y>() = 1.2f;
225 v.template get<P::z>() = 1.3f;
226 v.template get<P::s>() = 1.0f;
228 v.template get<P::v>()[0] = 1.0f;
229 v.template get<P::v>()[1] = 2.0f;
230 v.template get<P::v>()[2] = 3.0f;
232 v.template get<P::t>()[0][0] = 1.0f;
233 v.template get<P::t>()[0][1] = 2.0f;
234 v.template get<P::t>()[0][2] = 3.0f;
235 v.template get<P::t>()[1][0] = 4.0f;
236 v.template get<P::t>()[1][1] = 5.0f;
237 v.template get<P::t>()[1][2] = 6.0f;
238 v.template get<P::t>()[2][0] = 7.0f;
239 v.template get<P::t>()[2][1] = 8.0f;
240 v.template get<P::t>()[2][2] = 9.0f;
260 std::cout <<
"End : " << pow(sz,dim)*16*4/1024/1024 <<
" MB " <<
" Bandwidth: " << pow(sz,dim)*16*4/1024/1024/t.getect() <<
" MB/s " <<
"\n";
270 key_it = c3.getIterator();
272 while (key_it.isNext())
276 if (c3.template get<P::x>(kk) != c3.getGrid().LinId(kk)) passed =
false;
277 if (c3.template get<P::y>(kk) != c3.getGrid().LinId(kk)+1) passed =
false;
278 if (c3.template get<P::z>(kk) != c3.getGrid().LinId(kk)+2) passed =
false;
279 if (c3.template get<P::s>(kk) != c3.getGrid().LinId(kk)+3) passed =
false;
281 if (c3.template get<P::v>(kk)[0] != c3.getGrid().LinId(kk)+123) passed =
false;
282 if (c3.template get<P::v>(kk)[1] != c3.getGrid().LinId(kk)+124) passed =
false;
283 if (c3.template get<P::v>(kk)[2] != c3.getGrid().LinId(kk)+125) passed =
false;
285 if (c3.template get<P::t>(kk)[0][0] != c3.getGrid().LinId(kk)+567) passed =
false;
286 if (c3.template get<P::t>(kk)[0][1] != c3.getGrid().LinId(kk)+568) passed =
false;
287 if (c3.template get<P::t>(kk)[0][2] != c3.getGrid().LinId(kk)+569) passed =
false;
288 if (c3.template get<P::t>(kk)[1][0] != c3.getGrid().LinId(kk)+570) passed =
false;
289 if (c3.template get<P::t>(kk)[1][1] != c3.getGrid().LinId(kk)+571) passed =
false;
290 if (c3.template get<P::t>(kk)[1][2] != c3.getGrid().LinId(kk)+572) passed =
false;
291 if (c3.template get<P::t>(kk)[2][0] != c3.getGrid().LinId(kk)+573) passed =
false;
292 if (c3.template get<P::t>(kk)[2][1] != c3.getGrid().LinId(kk)+574) passed =
false;
293 if (c3.template get<P::t>(kk)[2][2] != c3.getGrid().LinId(kk)+575) passed =
false;
298 BOOST_REQUIRE_EQUAL(passed,
true);
301 template<
unsigned int dim,
typename g>
void test_layout_gridNd(g & c3,
size_t sz)
304 std::cout << dim <<
"D Array with grid_key (without redundant dimension): " <<
"\n";
319 c3.template get<P::x>(kk) = 1.1f;
320 c3.template get<P::y>(kk) = 1.2f;
321 c3.template get<P::z>(kk) = 1.3f;
322 c3.template get<P::s>(kk) = 1.0f;
324 c3.template get<P::v>(kk)[0] = 1.0f;
325 c3.template get<P::v>(kk)[1] = 2.0f;
326 c3.template get<P::v>(kk)[2] = 3.0f;
328 c3.template get<P::t>(kk)[0][0] = 1.0f;
329 c3.template get<P::t>(kk)[0][1] = 2.0f;
330 c3.template get<P::t>(kk)[0][2] = 3.0f;
331 c3.template get<P::t>(kk)[1][0] = 4.0f;
332 c3.template get<P::t>(kk)[1][1] = 5.0f;
333 c3.template get<P::t>(kk)[1][2] = 6.0f;
334 c3.template get<P::t>(kk)[2][0] = 7.0f;
335 c3.template get<P::t>(kk)[2][1] = 8.0f;
336 c3.template get<P::t>(kk)[2][2] = 9.0f;
346 std::cout <<
"End : " << pow(sz,dim)*16*4/1024/1024 <<
" MB " <<
" Bandwidth: " << pow(sz,dim)*16*4/1024/1024/t.
getwct() <<
" MB/s " <<
"\n";
353 key_it = c3.getIterator();
359 c3.template get<P::x>(kk) = c3.getGrid().LinId(kk);
360 c3.template get<P::y>(kk) = c3.getGrid().LinId(kk)+1;
361 c3.template get<P::z>(kk) = c3.getGrid().LinId(kk)+2;
362 c3.template get<P::s>(kk) = c3.getGrid().LinId(kk)+3;
364 c3.template get<P::v>(kk)[0] = c3.getGrid().LinId(kk)+123;
365 c3.template get<P::v>(kk)[1] = c3.getGrid().LinId(kk)+124;
366 c3.template get<P::v>(kk)[2] = c3.getGrid().LinId(kk)+125;
368 c3.template get<P::t>(kk)[0][0] = c3.getGrid().LinId(kk)+567;
369 c3.template get<P::t>(kk)[0][1] = c3.getGrid().LinId(kk)+568;
370 c3.template get<P::t>(kk)[0][2] = c3.getGrid().LinId(kk)+569;
371 c3.template get<P::t>(kk)[1][0] = c3.getGrid().LinId(kk)+570;
372 c3.template get<P::t>(kk)[1][1] = c3.getGrid().LinId(kk)+571;
373 c3.template get<P::t>(kk)[1][2] = c3.getGrid().LinId(kk)+572;
374 c3.template get<P::t>(kk)[2][0] = c3.getGrid().LinId(kk)+573;
375 c3.template get<P::t>(kk)[2][1] = c3.getGrid().LinId(kk)+574;
376 c3.template get<P::t>(kk)[2][2] = c3.getGrid().LinId(kk)+575;
382 key_it = c3.getIterator();
388 if (c3.template get<P::x>(kk) != c3.getGrid().LinId(kk)) passed =
false;
389 if (c3.template get<P::y>(kk) != c3.getGrid().LinId(kk)+1) passed =
false;
390 if (c3.template get<P::z>(kk) != c3.getGrid().LinId(kk)+2) passed =
false;
391 if (c3.template get<P::s>(kk) != c3.getGrid().LinId(kk)+3) passed =
false;
393 if (c3.template get<P::v>(kk)[0] != c3.getGrid().LinId(kk)+123) passed =
false;
394 if (c3.template get<P::v>(kk)[1] != c3.getGrid().LinId(kk)+124) passed =
false;
395 if (c3.template get<P::v>(kk)[2] != c3.getGrid().LinId(kk)+125) passed =
false;
397 if (c3.template get<P::t>(kk)[0][0] != c3.getGrid().LinId(kk)+567) passed =
false;
398 if (c3.template get<P::t>(kk)[0][1] != c3.getGrid().LinId(kk)+568) passed =
false;
399 if (c3.template get<P::t>(kk)[0][2] != c3.getGrid().LinId(kk)+569) passed =
false;
400 if (c3.template get<P::t>(kk)[1][0] != c3.getGrid().LinId(kk)+570) passed =
false;
401 if (c3.template get<P::t>(kk)[1][1] != c3.getGrid().LinId(kk)+571) passed =
false;
402 if (c3.template get<P::t>(kk)[1][2] != c3.getGrid().LinId(kk)+572) passed =
false;
403 if (c3.template get<P::t>(kk)[2][0] != c3.getGrid().LinId(kk)+573) passed =
false;
404 if (c3.template get<P::t>(kk)[2][1] != c3.getGrid().LinId(kk)+574) passed =
false;
405 if (c3.template get<P::t>(kk)[2][2] != c3.getGrid().LinId(kk)+575) passed =
false;
410 BOOST_REQUIRE_EQUAL(passed,
true);
439 key_it = c3.getIterator();
445 c3.template get<P::x>(kk) = 0.0;
450 for(
size_t i = 0 ; i <= dim ; i++)
457 for (
size_t j = 0 ; j < combs.size() ; j++)
466 for (
size_t k = 0 ; k < dim ; k++)
470 if (combs[j].c[k] == -1)
475 else if (combs[j].c[k] == 1)
477 start.
set_d(k,c3.getGrid().size(k)-1);
478 stop.
set_d(k,c3.getGrid().size(k)-1);
483 stop.
set_d(k,c3.getGrid().size(k)-2);
487 bool make_test =
true;
496 if (make_test ==
true)
498 auto key_it = c3.getSubIterator(start,stop);
504 BOOST_REQUIRE_EQUAL(c3.template get<P::x>(kk),0.0);
506 c3.template get<P::x>(kk) = 1.0;
516 key_it = c3.getIterator();
522 BOOST_REQUIRE_EQUAL(c3.template get<P::x>(kk),1.0);
528 BOOST_AUTO_TEST_SUITE( grid_test )
536 size_t sz[] = {16,16,16};
547 BOOST_AUTO_TEST_CASE( grid_safety_check )
549 #if defined(SE_CLASS1) && defined (THROW_ON_ERROR)
555 size_t sz[] = {16,16,16};
569 {g.get<p::x>(keyOut);}
570 catch (std::exception & e)
573 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime grid error");
575 BOOST_REQUIRE_EQUAL(error,
true);
580 {g.get<p::x>(keyOut);}
581 catch (std::exception & e)
584 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime grid error");
586 BOOST_REQUIRE_EQUAL(error,
true);
592 catch (std::exception & e)
595 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime grid error");
597 BOOST_REQUIRE_EQUAL(error,
true);
601 {g.set(keyGood,g2,keyOut);}
602 catch (std::exception & e)
605 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime grid error");
607 BOOST_REQUIRE_EQUAL(error,
true);
613 {g.get<p::x>(keyNeg);}
614 catch (std::exception & e)
617 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime grid error");
619 BOOST_REQUIRE_EQUAL(error,
true);
625 catch (std::exception & e)
628 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime grid error");
630 BOOST_REQUIRE_EQUAL(error,
true);
634 {g.set(keyGood,g2,keyNeg);}
635 catch (std::exception & e)
638 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime grid error");
640 BOOST_REQUIRE_EQUAL(error,
true);
642 #if defined(SE_CLASS2) && defined (THROW_ON_ERROR)
655 catch (std::exception & e)
658 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime memory error");
660 BOOST_REQUIRE_EQUAL(error,
true);
665 catch (std::exception & e)
668 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime memory error");
670 BOOST_REQUIRE_EQUAL(error,
true);
677 BOOST_AUTO_TEST_CASE( grid_use)
682 std::cout <<
"Grid unit test start" <<
"\n";
684 size_t sz[3] = {GS_SIZE,GS_SIZE,GS_SIZE};
691 #ifndef TEST_COVERAGE_MODE
695 test_all_grid<5>(18);
696 test_all_grid<4>(37);
697 test_all_grid<3>(126);
698 test_all_grid<2>(1414);
699 test_all_grid<1>(2000000);
714 test_all_grid<2>(16);
715 test_all_grid<1>(256);
720 for (
int i = 0 ; i <= GS_SIZE ; i++)
729 test_layout_grid3d(c3,i);
736 test_layout_grid3d(c3,i);}
743 test_layout_grid3d(c3,i);}
749 test_layout_grid3d(c3,i);}
753 std::cout <<
"Grid unit test end" <<
"\n";
762 BOOST_AUTO_TEST_CASE( C_array_test )
767 std::cout <<
"Grid size known at runtime" <<
"\n";
768 std::cout <<
"1D Array with index calculation: " <<
"\n";
773 int gs_sq = GS_SIZE*GS_SIZE;
781 for (
int i = 0 ; i < GS_SIZE ; i++)
783 for (
int j = 0 ; j < GS_SIZE ; j++)
785 for (
int k = 0 ; k < GS_SIZE ; k++)
787 pA[i*gs_sq+j*gs+k].x = 1.1f;
788 pA[i*gs_sq+j*gs+k].y = 1.2f;
789 pA[i*gs_sq+j*gs+k].z = 1.3f;
790 pA[i*gs_sq+j*gs+k].s = 1.0f;
792 pA[i*gs_sq+j*gs+k].v[0] = 1.0f;
793 pA[i*gs_sq+j*gs+k].v[1] = 2.0f;
794 pA[i*gs_sq+j*gs+k].v[2] = 3.0f;
796 pA[i*gs_sq+j*gs+k].t[0][0] = 1.0f;
797 pA[i*gs_sq+j*gs+k].t[0][1] = 2.0f;
798 pA[i*gs_sq+j*gs+k].t[0][2] = 3.0f;
799 pA[i*gs_sq+j*gs+k].t[1][0] = 4.0f;
800 pA[i*gs_sq+j*gs+k].t[1][1] = 5.0f;
801 pA[i*gs_sq+j*gs+k].t[1][2] = 6.0f;
802 pA[i*gs_sq+j*gs+k].t[2][0] = 7.0f;
803 pA[i*gs_sq+j*gs+k].t[2][1] = 8.0f;
804 pA[i*gs_sq+j*gs+k].t[2][2] = 9.0f;
814 std::cout <<
"End : " << GS_SIZE*GS_SIZE*GS_SIZE*16*4/1024/1024 <<
" MB " <<
" Bandwidth: " << GS_SIZE*GS_SIZE*GS_SIZE*16*4/1024/1024/t.
getcputime() <<
" MB/s \n";
818 BOOST_AUTO_TEST_CASE(grid_operator_equal)
822 size_t sz[] = {16,16};
829 auto it = g1.getIterator();
835 g1.get<b::p1>(
key)[0] =
key.get(0);
836 g1.get<b::p2>(
key)[1] =
key.get(1);
846 bool ret = (g2 == g1);
848 BOOST_REQUIRE_EQUAL(ret,
true);
862 auto it1 = g1.getIterator();
866 auto key = it1.get();
868 g1.get<b::p1>(
key)[0] =
key.get(0);
869 g1.get<b::p2>(
key)[1] =
key.get(1);
874 auto it2 = g2.getIterator();
878 auto key = it2.get();
880 g2.get<b::p1>(
key)[0] =
key.get(0);
881 g2.get<b::p2>(
key)[1] =
key.get(1);
889 BOOST_AUTO_TEST_CASE(grid_operator_swap)
891 size_t sz1[] = {16,16};
892 size_t sz2[] = {5,5};
903 fill_2_grid_data(g1_old,g2_old);
904 fill_2_grid_data(g1,g2);
912 bool ret = (g2 == g1_old);
913 BOOST_REQUIRE_EQUAL(ret,
true);
914 ret = (g1 == g2_old);
915 BOOST_REQUIRE_EQUAL(ret,
true);
918 BOOST_AUTO_TEST_CASE(grid_resize_less)
920 size_t sz1[] = {256,256};
921 size_t sz2[] = {5,5};
926 fill_2_grid_data(g1,g1);
931 BOOST_REQUIRE_EQUAL(g1.size(),25ul);
934 BOOST_AUTO_TEST_SUITE_END()
static std::vector< comb< dim > > getCombinations_R(size_t d)
grid_key_dx is the key to access any element in the grid
double getwct()
Return the elapsed real time.
mem_id get(size_t i) const
Get the i index.
double getcputime()
Return the cpu time.
It model an expression expr1 * expr2.
const grid_key_dx< dim > & get() const
Get the actual key.
void start()
Start the timer.
bool isNext()
Check if there is the next element.
This class represent an N-dimensional box.
This class is a trick to indicate the compiler a specific specialization pattern. ...
void set(a v, T...t)
set the Key from a list of numbers
Definition of a class Point in plain C++ and boost::vector for testing purpose.
void set_d(size_t i, mem_id id)
Set the i index.
Test structure used for several test.
Class for cpu time benchmarking.
void stop()
Stop the timer.