8#ifndef BOX_UNIT_TESTS_HPP_
9#define BOX_UNIT_TESTS_HPP_
11BOOST_AUTO_TEST_SUITE( box_test )
13BOOST_AUTO_TEST_CASE( box_use)
15 std::cout <<
"Box unit test start" <<
"\n";
19 float spacing[2] = {0.1,0.1};
24 BOOST_REQUIRE_CLOSE(sp.getLow(0),1.0,0.0001);
25 BOOST_REQUIRE_CLOSE(sp.getLow(1),1.0,0.0001);
27 BOOST_REQUIRE_CLOSE(sp.getHigh(0),2.1,0.0001);
28 BOOST_REQUIRE_CLOSE(sp.getHigh(1),3.1,0.0001);
40 BOOST_REQUIRE_EQUAL(box1.getLow(0),0.1f);
41 BOOST_REQUIRE_EQUAL(box1.getLow(1),0.2f);
42 BOOST_REQUIRE_EQUAL(box1.getLow(2),0.3f);
44 BOOST_REQUIRE_EQUAL(box1.getHigh(0),2.0f);
45 BOOST_REQUIRE_EQUAL(box1.getHigh(1),2.1f);
46 BOOST_REQUIRE_EQUAL(box1.getHigh(2),2.2f);
64 BOOST_REQUIRE_CLOSE(box1.getHigh(0),1.0f,0.0001);
65 BOOST_REQUIRE_CLOSE(box1.getHigh(1),0.1f,0.0001);
66 BOOST_REQUIRE_CLOSE(box1.getHigh(2),1.0f,0.0001);
79 BOOST_REQUIRE_CLOSE(box1.getLow(0),-0.4,0.0001);
80 BOOST_REQUIRE_CLOSE(box1.getLow(1),-0.4,0.0001);
81 BOOST_REQUIRE_CLOSE(box1.getLow(2),-0.4,0.0001);
83 BOOST_REQUIRE_CLOSE(box1.getHigh(0),1.5,0.0001);
84 BOOST_REQUIRE_CLOSE(box1.getHigh(1),1.7,0.0001);
85 BOOST_REQUIRE_CLOSE(box1.getHigh(2),2.0,0.0001);
98 BOOST_REQUIRE_CLOSE(box1.getLow(0),0.1,0.0001);
99 BOOST_REQUIRE_CLOSE(box1.getLow(1),0.2,0.0001);
100 BOOST_REQUIRE_CLOSE(box1.getLow(2),0.3,0.0001);
102 BOOST_REQUIRE_CLOSE(box1.getHigh(0),2.0,0.0001);
103 BOOST_REQUIRE_CLOSE(box1.getHigh(1),2.3,0.0001);
104 BOOST_REQUIRE_CLOSE(box1.getHigh(2),2.7,0.0001);
116 BOOST_REQUIRE_CLOSE(box1.getLow(0),0.1001,0.001);
117 BOOST_REQUIRE_CLOSE(box1.getLow(1),0.2002,0.001);
118 BOOST_REQUIRE_CLOSE(box1.getLow(2),0.3003,0.001);
120 BOOST_REQUIRE_CLOSE(box1.getHigh(0),1.001,0.00001);
121 BOOST_REQUIRE_CLOSE(box1.getHigh(1),1.1011,0.00001);
122 BOOST_REQUIRE_CLOSE(box1.getHigh(2),1.3013,0.00001);
125 BOOST_REQUIRE_CLOSE(box1.getHigh(0) - box1.getLow(0), 1.001 * 0.9 ,0.001);
126 BOOST_REQUIRE_CLOSE(box1.getHigh(1) - box1.getLow(1), 1.001 * 0.9, 0.001);
127 BOOST_REQUIRE_CLOSE(box1.getHigh(2) - box1.getLow(2), 1.001 * 1.0, 0.001);
139 BOOST_REQUIRE_CLOSE(box1.getLow(0),0.1,0.0001);
140 BOOST_REQUIRE_CLOSE(box1.getLow(1),0.2,0.0001);
141 BOOST_REQUIRE_CLOSE(box1.getLow(2),0.3,0.0001);
143 BOOST_REQUIRE_CLOSE(box1.getHigh(0),1.0009,0.00001);
144 BOOST_REQUIRE_CLOSE(box1.getHigh(1),1.1009,0.00001);
145 BOOST_REQUIRE_CLOSE(box1.getHigh(2),1.301,0.00001);
148 BOOST_REQUIRE_CLOSE(box1.getHigh(0) - box1.getLow(0), 1.001 * 0.9 ,0.00001);
149 BOOST_REQUIRE_CLOSE(box1.getHigh(1) - box1.getLow(1), 1.001 * 0.9, 0.00001);
150 BOOST_REQUIRE_CLOSE(box1.getHigh(2) - box1.getLow(2), 1.001 * 1.0, 0.00001);
163 BOOST_REQUIRE_CLOSE(box1.
getLow(0),0.0,0.0001);
164 BOOST_REQUIRE_CLOSE(box1.
getLow(1),0.3,0.0001);
165 BOOST_REQUIRE_CLOSE(box1.
getLow(2),0.3,0.0001);
167 BOOST_REQUIRE_CLOSE(box1.
getHigh(0),0.9,0.0001);
168 BOOST_REQUIRE_CLOSE(box1.
getHigh(1),1.0,0.0001);
169 BOOST_REQUIRE_CLOSE(box1.
getHigh(2),1.1,0.0001);
173 box1 -= box1.
getP2();
175 BOOST_REQUIRE_CLOSE(box1.
getLow(0),-0.9,0.0001);
176 BOOST_REQUIRE_CLOSE(box1.
getLow(1),-0.7,0.0001);
177 BOOST_REQUIRE_CLOSE(box1.
getLow(2),-0.8,0.0001);
179 BOOST_REQUIRE_CLOSE(box1.
getHigh(0),0.0,0.0001);
180 BOOST_REQUIRE_CLOSE(box1.
getHigh(1),0.0,0.0001);
181 BOOST_REQUIRE_CLOSE(box1.
getHigh(2),0.0,0.0001);
183 box1 -= box1.
getP1();
185 BOOST_REQUIRE_CLOSE(box1.
getLow(0),0.0,0.0001);
186 BOOST_REQUIRE_CLOSE(box1.
getLow(1),0.0,0.0001);
187 BOOST_REQUIRE_CLOSE(box1.
getLow(2),0.0,0.0001);
189 BOOST_REQUIRE_CLOSE(box1.
getHigh(0),0.9,0.0001);
190 BOOST_REQUIRE_CLOSE(box1.
getHigh(1),0.7,0.0001);
191 BOOST_REQUIRE_CLOSE(box1.
getHigh(2),0.8,0.0001);
203 BOOST_REQUIRE_EQUAL(val,
false);
205 BOOST_REQUIRE_EQUAL(invalid2.isValid(),
false);
207 BOOST_REQUIRE_EQUAL(invalid3.isValid(),
false);
209 BOOST_REQUIRE_EQUAL(valid1.isValid(),
true);
211 BOOST_REQUIRE_EQUAL(valid2.isValid(),
true);
224 BOOST_REQUIRE_CLOSE(result.
getHigh(0),4.2,0.0001);
225 BOOST_REQUIRE_CLOSE(result.
getHigh(1),5.2,0.0001);
227 BOOST_REQUIRE_CLOSE(result.
getLow(0),1.5,0.0001);
228 BOOST_REQUIRE_CLOSE(result.
getLow(1),2.4,0.0001);
241 BOOST_REQUIRE_EQUAL(box.isInsideNP(p1),
true);
242 BOOST_REQUIRE_EQUAL(box.isInsideNP(p2),
true);
243 BOOST_REQUIRE_EQUAL(box.isInsideNP(p3),
false);
256 BOOST_REQUIRE_EQUAL(box.isInside(p1),
true);
257 BOOST_REQUIRE_EQUAL(box.isInside(p2),
true);
258 BOOST_REQUIRE_EQUAL(box.isInside(p3),
true);
271 BOOST_REQUIRE_EQUAL(box.isInsideNB(p1),
false);
272 BOOST_REQUIRE_EQUAL(box.isInsideNB(p2),
true);
273 BOOST_REQUIRE_EQUAL(box.isInsideNB(p3),
false);
281 bool ret = (b1 == b2);
283 BOOST_REQUIRE_EQUAL(ret,
true);
287 BOOST_REQUIRE_EQUAL(b1.isValid(),
false);
289 std::cout <<
"Box unit test stop" <<
"\n";
292BOOST_AUTO_TEST_CASE( box_min_distance_test )
309 BOOST_REQUIRE_EQUAL(b1.min_distance(b2),0.0);
310 BOOST_REQUIRE_EQUAL(b1.min_distance(b3),0.0);
311 BOOST_REQUIRE_EQUAL(b1.min_distance(b4),0.0);
312 BOOST_REQUIRE_EQUAL(b1.min_distance(b5),0.0);
313 BOOST_REQUIRE_EQUAL(b1.min_distance(b6),0.0);
314 BOOST_REQUIRE_EQUAL(b1.min_distance(b7),0.0);
315 BOOST_REQUIRE_EQUAL(b1.min_distance(b8),0.0);
316 BOOST_REQUIRE_EQUAL(b1.min_distance(b9),0.0);
317 BOOST_REQUIRE_EQUAL(b1.min_distance(b10),0.0);
333 BOOST_REQUIRE_CLOSE(b1.min_distance(b2),0.1,0.01);
334 BOOST_REQUIRE_CLOSE(b1.min_distance(b3),0.1,0.01);
335 BOOST_REQUIRE_CLOSE(b1.min_distance(b4),0.1,0.01);
336 BOOST_REQUIRE_CLOSE(b1.min_distance(b5),0.1,0.01);
337 BOOST_REQUIRE_CLOSE(b1.min_distance(b6),0.1,0.01);
338 BOOST_REQUIRE_CLOSE(b1.min_distance(b7),0.1,0.01);
339 BOOST_REQUIRE_CLOSE(b1.min_distance(b8),0.1,0.01);
340 BOOST_REQUIRE_CLOSE(b1.min_distance(b9),0.1,0.01);
341 BOOST_REQUIRE_CLOSE(b1.min_distance(b10),0.1,0.01);
358 BOOST_REQUIRE_CLOSE(b1.min_distance(b2),sqrt(0.01 + 0.01),0.01);
359 BOOST_REQUIRE_CLOSE(b1.min_distance(b3),sqrt(0.01 + 0.01),0.01);
360 BOOST_REQUIRE_CLOSE(b1.min_distance(b4),sqrt(0.01 + 0.01),0.01);
361 BOOST_REQUIRE_CLOSE(b1.min_distance(b5),sqrt(0.01 + 0.01),0.01);
362 BOOST_REQUIRE_CLOSE(b1.min_distance(b6),sqrt(0.01 + 0.01),0.01);
363 BOOST_REQUIRE_CLOSE(b1.min_distance(b7),sqrt(0.01 + 0.01),0.01);
364 BOOST_REQUIRE_CLOSE(b1.min_distance(b8),sqrt(0.01 + 0.01),0.01);
365 BOOST_REQUIRE_CLOSE(b1.min_distance(b9),sqrt(0.01 + 0.01),0.01);
366 BOOST_REQUIRE_CLOSE(b1.min_distance(b10),sqrt(0.01 + 0.01),0.01);
369BOOST_AUTO_TEST_CASE( box_is_inside_with_border )
373 size_t bc_nn[] = {NON_PERIODIC,NON_PERIODIC};
374 size_t bc_pn[] = {PERIODIC,NON_PERIODIC};
375 size_t bc_np[] = {NON_PERIODIC,PERIODIC};
376 size_t bc_pp[] = {PERIODIC,PERIODIC};
394 bool result = b2.isInsideNP_with_border(p1,border,bc_nn);
395 BOOST_REQUIRE_EQUAL(result,
true);
397 result = b2.isInsideNP_with_border(p2,border,bc_nn);
398 BOOST_REQUIRE_EQUAL(result,
false);
400 result = b2.isInsideNP_with_border(p3,border,bc_nn);
401 BOOST_REQUIRE_EQUAL(result,
false);
405 BOOST_REQUIRE_EQUAL(result,
true);
408 BOOST_REQUIRE_EQUAL(result,
true);
411 BOOST_REQUIRE_EQUAL(result,
true);
414 BOOST_REQUIRE_EQUAL(result,
true);
418 result = b2.isInsideNP_with_border(p1,border,bc_pn);
419 BOOST_REQUIRE_EQUAL(result,
true);
421 result = b2.isInsideNP_with_border(p2,border,bc_pn);
422 BOOST_REQUIRE_EQUAL(result,
false);
424 result = b2.isInsideNP_with_border(p3,border,bc_pn);
425 BOOST_REQUIRE_EQUAL(result,
false);
429 BOOST_REQUIRE_EQUAL(result,
true);
432 BOOST_REQUIRE_EQUAL(result,
true);
435 BOOST_REQUIRE_EQUAL(result,
true);
438 BOOST_REQUIRE_EQUAL(result,
true);
442 result = b2.isInsideNP_with_border(p1,border,bc_np);
443 BOOST_REQUIRE_EQUAL(result,
true);
445 result = b2.isInsideNP_with_border(p2,border,bc_np);
446 BOOST_REQUIRE_EQUAL(result,
false);
448 result = b2.isInsideNP_with_border(p3,border,bc_np);
449 BOOST_REQUIRE_EQUAL(result,
false);
453 BOOST_REQUIRE_EQUAL(result,
true);
456 BOOST_REQUIRE_EQUAL(result,
true);
459 BOOST_REQUIRE_EQUAL(result,
false);
462 BOOST_REQUIRE_EQUAL(result,
false);
466 result = b2.isInsideNP_with_border(p1,border,bc_pp);
467 BOOST_REQUIRE_EQUAL(result,
true);
469 result = b2.isInsideNP_with_border(p2,border,bc_pp);
470 BOOST_REQUIRE_EQUAL(result,
false);
472 result = b2.isInsideNP_with_border(p3,border,bc_pp);
473 BOOST_REQUIRE_EQUAL(result,
false);
477 BOOST_REQUIRE_EQUAL(result,
true);
480 BOOST_REQUIRE_EQUAL(result,
true);
483 BOOST_REQUIRE_EQUAL(result,
false);
486 BOOST_REQUIRE_EQUAL(result,
false);
489BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
void enlarge_fix_P1(Box< dim, S > &gh)
Enlarge the box with ghost margin keeping fix the point P1.
void expand(T(&exp)[dim])
expand the box by a vector
Point< dim, T > getP2() const
Get the point p2.
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
__device__ __host__ T getHigh(int i) const
get the high interval of the box
void magnify_fix_P1(T mg)
Magnify the box by a factor keeping fix the point P1.
void enlarge(const Box< dim, T > &gh)
Enlarge the box with ghost margin.
bool isValid() const
Check if the Box is a valid box P2 >= P1.
void magnify(T mg)
Magnify the box.
void contained(const Box< dim, T > &en, const bool reset_p1=true)
Refine the box to be contained in the given box and itself.
Point< dim, T > getP1() const
Get the point p1.
void enclose(const Box< dim, T > &en)
Refine the box to enclose the given box and itself.
__device__ __host__ bool isInsideNP_with_border(const Point< dim, T > &p, const Box< dim, T > &border, const bc_type(&bc)[dim]) const
Check if the point is inside the region excluding the positive part.
This class implement the point shape in an N-dimensional space.