8 #ifndef SPACEBOX_UNIT_TESTS_HPP_
9 #define SPACEBOX_UNIT_TESTS_HPP_
11 #include "SpaceBox.hpp"
13 #define N_RANDOM_POINT 1024
15 BOOST_AUTO_TEST_SUITE( spacebox_test )
17 BOOST_AUTO_TEST_CASE( spacebox_use)
19 std::cout <<
"SpaceBox unit test start" <<
"\n";
23 float spacing[2] = {0.1,0.1};
29 BOOST_REQUIRE_CLOSE(sp.getLow(0),1.0,0.0001);
30 BOOST_REQUIRE_CLOSE(sp.getLow(1),1.0,0.0001);
31 BOOST_REQUIRE_CLOSE(sp.getHigh(0),1.1,0.0001);
32 BOOST_REQUIRE_CLOSE(sp.getHigh(1),1.1,0.0001);
42 BOOST_REQUIRE_CLOSE(sp.getLow(0),0.1,0.0001);
43 BOOST_REQUIRE_CLOSE(sp.getLow(1),0.1,0.0001);
44 BOOST_REQUIRE_CLOSE(sp.getHigh(0),0.3,0.0001);
45 BOOST_REQUIRE_CLOSE(sp.getHigh(1),0.3,0.0001);
57 BOOST_REQUIRE_EQUAL(inte,
true);
58 BOOST_REQUIRE_EQUAL(sp3.
getLow(0),1.0);
59 BOOST_REQUIRE_EQUAL(sp3.
getLow(1),1.0);
60 BOOST_REQUIRE_EQUAL(sp3.
getHigh(0),1.5);
61 BOOST_REQUIRE_EQUAL(sp3.
getHigh(1),1.5);
65 sp1.set({0.0,0.0},{1.0,1.0});
66 sp2.set({0.2,-0.5},{0.4,1.5});
68 inte = sp1.Intersect(sp2,sp3);
70 BOOST_REQUIRE_EQUAL(inte,
true);
71 BOOST_REQUIRE_EQUAL(sp3.
getLow(0),0.2f);
72 BOOST_REQUIRE_EQUAL(sp3.
getLow(1),0.0f);
73 BOOST_REQUIRE_EQUAL(sp3.
getHigh(0),0.4f);
74 BOOST_REQUIRE_EQUAL(sp3.
getHigh(1),1.0f);
76 sp1.set({0.0,0.0},{1.0,1.0});
77 sp2.set({0.2,0.2},{0.4,0.4});
79 inte = sp1.Intersect(sp2,sp3);
81 BOOST_REQUIRE_EQUAL(inte,
true);
82 BOOST_REQUIRE_EQUAL(sp3.
getLow(0),0.2f);
83 BOOST_REQUIRE_EQUAL(sp3.
getLow(1),0.2f);
84 BOOST_REQUIRE_EQUAL(sp3.
getHigh(0),0.4f);
85 BOOST_REQUIRE_EQUAL(sp3.
getHigh(1),0.4f);
87 sp1.set({0.0,0.0},{1.0,1.0});
88 sp2.set({1.2,0.0},{2.4,1.0});
90 inte = sp1.Intersect(sp2,sp3);
92 BOOST_REQUIRE_EQUAL(inte,
false);
97 sp1.set({0.0,0.0},{1.0,1.0});
98 sp2.set({0.5,0.1},{0.5,1.1});
100 inte = sp1.Intersect(sp2,sp3);
102 BOOST_REQUIRE_EQUAL(inte,
true);
103 BOOST_REQUIRE_EQUAL(sp3.
getLow(0),0.5f);
104 BOOST_REQUIRE_EQUAL(sp3.
getLow(1),0.1f);
105 BOOST_REQUIRE_EQUAL(sp3.
getHigh(0),0.5f);
106 BOOST_REQUIRE_EQUAL(sp3.
getHigh(1),1.0f);
110 sp1.set({0.0,0.0},{1.0,1.0});
111 sp2.set({1.0,0.0},{1.5,1.5});
113 inte = sp1.Intersect(sp2,sp3);
115 BOOST_REQUIRE_EQUAL(inte,
true);
116 BOOST_REQUIRE_EQUAL(sp3.
getLow(0),1.0f);
117 BOOST_REQUIRE_EQUAL(sp3.
getLow(1),0.0f);
118 BOOST_REQUIRE_EQUAL(sp3.
getHigh(0),1.0f);
119 BOOST_REQUIRE_EQUAL(sp3.
getHigh(1),1.0f);
122 sp1.set({0.0,0.0},{1.0,1.0});
127 BOOST_REQUIRE_EQUAL(sp1.getLow(0),-0.5f);
128 BOOST_REQUIRE_EQUAL(sp1.getLow(1),-0.5f);
129 BOOST_REQUIRE_EQUAL(sp1.getHigh(0),1.5f);
130 BOOST_REQUIRE_EQUAL(sp1.getHigh(1),1.5f);
137 for (
int i = 0 ; i < N_RANDOM_POINT ; i++)
141 BOOST_REQUIRE_EQUAL(sp_box.isInside(p),
true);
150 for (
int i = 0 ; i < N_RANDOM_POINT ; i++)
154 BOOST_REQUIRE_EQUAL(sp_box.isInside(p),
false);
157 std::cout <<
"SpaceBox unit test stop" <<
"\n";
160 BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
T getLow(int i) const
get the i-coordinate of the low bound interval of the box
void mul(T(&sp)[dim])
multiply the space box with the coefficient defined in sp
T getHigh(int i) const
get the high interval of the box
This class implement the point shape in an N-dimensional space.
bool Intersect(const Box< dim, T > &b, Box< dim, T > &b_out) const
Intersect.
void rescale(T(&sp)[dim])
Re-scale the space box with the coefficient defined in sp.