1 #ifndef HYPERCUBE_UNIT_TEST_HPP
2 #define HYPERCUBE_UNIT_TEST_HPP
4 #include "Space/Shape/HyperCube.hpp"
5 #include "util/util_debug.hpp"
13 template<
unsigned int dim>
void check_lin(std::vector<
comb<dim>> cmb)
16 for (
size_t i = 0 ; i < cmb.size() ; i++)
28 template<
unsigned int dim>
void check_lin_perm(std::vector<
comb<dim>> cmb)
31 for (
size_t i = 0 ; i < cmb.size() ; i++)
43 template<
unsigned int dim>
bool isDinstict(std::vector<
comb<dim>> combs)
47 for (
size_t i = 0 ; i < combs.size() ; i++)
49 for (
size_t j = i+1 ; j < combs.size() ; j++)
51 if (combs[i] == combs[j])
69 template<
unsigned int dim>
bool isSubdecomposition(std::vector<
comb<dim>> combs,
comb<dim> c)
71 for (
size_t i = 0 ; i < combs.size() ; i++)
73 if (c.
isSub(combs[i]) ==
false)
80 template<
unsigned int dim>
bool isValid(std::vector<
comb<dim>> combs)
84 for (
size_t i = 0 ; i < combs.size() ; i++)
86 if (combs[i].isValid() ==
false)
93 BOOST_AUTO_TEST_SUITE( Hyper_cube )
95 BOOST_AUTO_TEST_CASE( Hyper_cube_comb_use )
103 BOOST_REQUIRE_EQUAL(c_ret.
c[0],2);
104 BOOST_REQUIRE_EQUAL(c_ret.
c[1],1);
105 BOOST_REQUIRE_EQUAL(c_ret.
c[2],0);
113 BOOST_REQUIRE_EQUAL(c2.
c[0],1);
114 BOOST_REQUIRE_EQUAL(c2.
c[1],0);
115 BOOST_REQUIRE_EQUAL(c2.
c[2],1);
124 BOOST_REQUIRE_EQUAL(c_ret.
c[0],4);
125 BOOST_REQUIRE_EQUAL(c_ret.
c[1],3);
126 BOOST_REQUIRE_EQUAL(c_ret.
c[2],2);
134 BOOST_REQUIRE_EQUAL(c_ret.
c[0],-3);
135 BOOST_REQUIRE_EQUAL(c_ret.
c[1],-2);
136 BOOST_REQUIRE_EQUAL(c_ret.
c[2],-1);
144 BOOST_REQUIRE_EQUAL(c_ret.
c[0],0);
145 BOOST_REQUIRE_EQUAL(c_ret.
c[1],-1);
146 BOOST_REQUIRE_EQUAL(c_ret.
c[2],-1);
150 BOOST_AUTO_TEST_CASE( Hyper_cube_use)
152 std::cout <<
"Hyper-cube unit test start" <<
"\n";
170 BOOST_REQUIRE_EQUAL(ele[0],2ul);
171 BOOST_REQUIRE_EQUAL(ele[1],1ul);
180 std::vector<comb<1>> v1_st;
182 check_lin_perm(v1_st);
184 boost_check_array(&c[0],&v_c1_0[0],2);
202 BOOST_REQUIRE_EQUAL(ele[0],4ul);
203 BOOST_REQUIRE_EQUAL(ele[1],4ul);
204 BOOST_REQUIRE_EQUAL(ele[2],1ul);
208 comb<2> c2_0[] = {{1,1},{-1,1},{1,-1},{-1,-1}};
209 comb<2> c2_1[] = {{0,1},{0,-1},{1,0},{-1,0}};
213 std::vector<comb<2>> v2_st;
215 check_lin_perm(v2_st);
217 boost_check_array(&c2_0[0],&v_c2_0[0],4);
218 boost_check_array(&c2_1[0],&v_c2_1[0],4);
240 BOOST_REQUIRE_EQUAL(ele[0],8ul);
241 BOOST_REQUIRE_EQUAL(ele[1],12ul);
242 BOOST_REQUIRE_EQUAL(ele[2],6ul);
243 BOOST_REQUIRE_EQUAL(ele[3],1ul);
247 comb<3> c3_0[] = {{1,1,1},{-1,1,1},{1,-1,1},{-1,-1,1},{1,1,-1},{-1,1,-1},{1,-1,-1},{-1,-1,-1}};
248 comb<3> c3_1[] = {{0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1},{1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1},{1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0}};
249 comb<3> c3_2[] = {{{0,0,1}},{{0,0,-1}},{{0,1,0}},{{0,-1,0}},{{1,0,0}},{{-1,0,0}}};
254 std::vector<comb<3>> v3_st;
256 check_lin_perm(v3_st);
258 boost_check_array(&c3_0[0],&v_c3_0[0],8);
259 boost_check_array(&c3_1[0],&v_c3_1[0],12);
260 boost_check_array(&c3_2[0],&v_c3_2[0],6);
284 std::vector<comb<4>> v4_st;
286 check_lin_perm(v1_st);
289 BOOST_REQUIRE_EQUAL(ele[0],16ul);
290 BOOST_REQUIRE_EQUAL(ele[1],32ul);
291 BOOST_REQUIRE_EQUAL(ele[2],24ul);
292 BOOST_REQUIRE_EQUAL(ele[3],8ul);
293 BOOST_REQUIRE_EQUAL(ele[4],1ul);
321 std::vector<comb<5>> v5_st;
323 check_lin_perm(v5_st);
326 BOOST_REQUIRE_EQUAL(ele[0],32ul);
327 BOOST_REQUIRE_EQUAL(ele[1],80ul);
328 BOOST_REQUIRE_EQUAL(ele[2],80ul);
329 BOOST_REQUIRE_EQUAL(ele[3],40ul);
330 BOOST_REQUIRE_EQUAL(ele[4],10ul);
331 BOOST_REQUIRE_EQUAL(ele[5],1ul);
340 for (
size_t i = 0 ; i < sc2_0.size() ; i++)
346 BOOST_REQUIRE_EQUAL(combs.size(),1ul);
347 BOOST_REQUIRE_EQUAL(isDinstict(combs),
true);
348 BOOST_REQUIRE_EQUAL(isValid(combs),
true);
349 BOOST_REQUIRE_EQUAL(isSubdecomposition(combs,sc2_0[i]),
true);
356 for (
size_t i = 0 ; i < sc2_1.size() ; i++)
363 BOOST_REQUIRE_EQUAL(combs.size(),2ul);
364 BOOST_REQUIRE_EQUAL(isDinstict(combs),
true);
365 BOOST_REQUIRE_EQUAL(isValid(combs),
true);
366 BOOST_REQUIRE_EQUAL(isSubdecomposition(combs,sc2_1[i]),
true);
372 BOOST_REQUIRE_EQUAL(combs.size(),1ul);
373 BOOST_REQUIRE_EQUAL(isDinstict(combs),
true);
374 BOOST_REQUIRE_EQUAL(isValid(combs),
true);
375 BOOST_REQUIRE_EQUAL(isSubdecomposition(combs,sc2_1[i]),
true);
382 for (
size_t i = 0 ; i < sc2_2.size() ; i++)
388 BOOST_REQUIRE_EQUAL(combs.size(),4ul);
389 BOOST_REQUIRE_EQUAL(isDinstict(combs),
true);
390 BOOST_REQUIRE_EQUAL(isValid(combs),
true);
391 BOOST_REQUIRE_EQUAL(isSubdecomposition(combs,sc2_2[i]),
true);
397 BOOST_REQUIRE_EQUAL(combs.size(),4ul);
398 BOOST_REQUIRE_EQUAL(isDinstict(combs),
true);
399 BOOST_REQUIRE_EQUAL(isValid(combs),
true);
400 BOOST_REQUIRE_EQUAL(isSubdecomposition(combs,sc2_2[i]),
true);
406 BOOST_REQUIRE_EQUAL(combs.size(),1ul);
407 BOOST_REQUIRE_EQUAL(isDinstict(combs),
true);
408 BOOST_REQUIRE_EQUAL(isValid(combs),
true);
409 BOOST_REQUIRE_EQUAL(isSubdecomposition(combs,sc2_2[i]),
true);
418 for (
size_t i = 0 ; i < sc3_0.size() ; i++)
424 BOOST_REQUIRE_EQUAL(combs.size(),1ul);
425 BOOST_REQUIRE_EQUAL(isDinstict(combs),
true);
426 BOOST_REQUIRE_EQUAL(isValid(combs),
true);
434 for (
size_t i = 0 ; i < sc3_1.size() ; i++)
440 BOOST_REQUIRE_EQUAL(combs.size(),2ul);
441 BOOST_REQUIRE_EQUAL(isDinstict(combs),
true);
442 BOOST_REQUIRE_EQUAL(isValid(combs),
true);
443 BOOST_REQUIRE_EQUAL(isSubdecomposition(combs,sc3_1[i]),
true);
449 BOOST_REQUIRE_EQUAL(combs.size(),1ul);
450 BOOST_REQUIRE_EQUAL(isDinstict(combs),
true);
451 BOOST_REQUIRE_EQUAL(isValid(combs),
true);
452 BOOST_REQUIRE_EQUAL(isSubdecomposition(combs,sc3_1[i]),
true);
459 for (
size_t i = 0 ; i < sc3_2.size() ; i++)
465 BOOST_REQUIRE_EQUAL(combs.size(),4ul);
466 BOOST_REQUIRE_EQUAL(isDinstict(combs),
true);
467 BOOST_REQUIRE_EQUAL(isValid(combs),
true);
468 BOOST_REQUIRE_EQUAL(isSubdecomposition(combs,sc3_2[i]),
true);
474 BOOST_REQUIRE_EQUAL(combs.size(),4ul);
475 BOOST_REQUIRE_EQUAL(isDinstict(combs),
true);
476 BOOST_REQUIRE_EQUAL(isValid(combs),
true);
477 BOOST_REQUIRE_EQUAL(isSubdecomposition(combs,sc3_2[i]),
true);
483 BOOST_REQUIRE_EQUAL(combs.size(),1ul);
484 BOOST_REQUIRE_EQUAL(isDinstict(combs),
true);
485 BOOST_REQUIRE_EQUAL(isValid(combs),
true);
486 BOOST_REQUIRE_EQUAL(isSubdecomposition(combs,sc3_2[i]),
true);
489 std::cout <<
"Hyper-cube unit test end" <<
"\n";
492 BOOST_AUTO_TEST_SUITE_END()
static size_t getNumberOfElements_R(size_t d)
Get the number of Elements of dimension d.
static std::vector< comb< dim > > getCombinations_R(size_t d)
Position of the element of dimension d in the hyper-cube of dimension dim.
static void BinPermutationsSt(std::vector< comb< dim >> &v)
Binary permutations.
bool isSub(comb< dim > cmb)
Check if the combination is a sub-element.
comb< dim > flip()
flip the coefficent of the combination to be < 0
static std::vector< comb< dim > > getCombinations_R(comb< dim > c, int d)
This class calculate elements of the hyper-cube.
char c[dim]
Array that store the combination.