8 #ifndef OPENFPM_DATA_SRC_UTIL_MATHUTIL_UNIT_TEST_HPP_
9 #define OPENFPM_DATA_SRC_UTIL_MATHUTIL_UNIT_TEST_HPP_
11 #include "mathutil.hpp"
13 BOOST_AUTO_TEST_SUITE( mathutil_test )
15 BOOST_AUTO_TEST_CASE( math )
19 size_t f = openfpm::math::factorial(0);
20 BOOST_REQUIRE_EQUAL(f,1ul);
22 f = openfpm::math::factorial(1);
23 BOOST_REQUIRE_EQUAL(f,1ul);
25 f = openfpm::math::factorial(7);
26 BOOST_REQUIRE_EQUAL(f,5040ul);
32 f = openfpm::math::C(7,0);
33 BOOST_REQUIRE_EQUAL(f,1ul);
35 f = openfpm::math::C(7,7);
36 BOOST_REQUIRE_EQUAL(f,1ul);
38 f = openfpm::math::C(7,2);
39 BOOST_REQUIRE_EQUAL(f,21ul);
45 f = openfpm::math::round_big_2(3);
46 BOOST_REQUIRE_EQUAL(f,4ul);
48 f = openfpm::math::round_big_2(7);
49 BOOST_REQUIRE_EQUAL(f,8ul);
51 f = openfpm::math::round_big_2(21);
52 BOOST_REQUIRE_EQUAL(f,32ul);
58 f = openfpm::math::pow(3,3);
59 BOOST_REQUIRE_EQUAL(f,27ul);
61 f = openfpm::math::pow(4,2);
62 BOOST_REQUIRE_EQUAL(f,16ul);
64 f = openfpm::math::pow(2,5);
65 BOOST_REQUIRE_EQUAL(f,32ul);
71 f = openfpm::math::positive_modulo(-1,3);
72 BOOST_REQUIRE_EQUAL(f,2ul);
74 f = openfpm::math::positive_modulo(-5,2);
75 BOOST_REQUIRE_EQUAL(f,1ul);
77 f = openfpm::math::positive_modulo(-7,5);
78 BOOST_REQUIRE_EQUAL(f,3ul);
84 float ff = openfpm::math::periodic(10.9,1.1,0.1);
85 BOOST_REQUIRE_CLOSE(ff,0.9,0.0001);
87 ff = openfpm::math::periodic(0.0,1.1,0.1);
88 BOOST_REQUIRE_CLOSE(ff,1.0,0.0001);
90 ff = openfpm::math::periodic(-7.0,1.1,0.1);
91 BOOST_REQUIRE_CLOSE(ff,1.0,0.0001);
94 ff = openfpm::math::periodic(-10.9,1.1,0.1);
95 BOOST_REQUIRE_CLOSE(ff,1.1,0.0001);
101 ff = openfpm::math::periodic(0.0,1.1,0.1);
102 BOOST_REQUIRE_CLOSE(ff,1.0,0.0001);
104 ff = openfpm::math::periodic(1.2,1.1,0.1);
105 BOOST_REQUIRE_CLOSE(ff,0.2,0.0001);
108 ff = openfpm::math::periodic(0.9,1.1,0.1);
109 BOOST_REQUIRE_CLOSE(ff,0.9,0.0001);
114 BOOST_AUTO_TEST_SUITE_END()