OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
mathutil_unit_test.hpp
1 /*
2  * mathutil_unit_test.hpp
3  *
4  * Created on: Dec 23, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_UTIL_MATHUTIL_UNIT_TEST_HPP_
9 #define OPENFPM_DATA_SRC_UTIL_MATHUTIL_UNIT_TEST_HPP_
10 
11 #include "mathutil.hpp"
12 
13 BOOST_AUTO_TEST_SUITE( mathutil_test )
14 
15 BOOST_AUTO_TEST_CASE( math )
16 {
18 
19  size_t f = openfpm::math::factorial(0);
20  BOOST_REQUIRE_EQUAL(f,1ul);
21 
22  f = openfpm::math::factorial(1);
23  BOOST_REQUIRE_EQUAL(f,1ul);
24 
25  f = openfpm::math::factorial(7);
26  BOOST_REQUIRE_EQUAL(f,5040ul);
27 
29 
31 
32  f = openfpm::math::C(7,0);
33  BOOST_REQUIRE_EQUAL(f,1ul);
34 
35  f = openfpm::math::C(7,7);
36  BOOST_REQUIRE_EQUAL(f,1ul);
37 
38  f = openfpm::math::C(7,2);
39  BOOST_REQUIRE_EQUAL(f,21ul);
40 
42 
44 
45  f = openfpm::math::round_big_2(3);
46  BOOST_REQUIRE_EQUAL(f,4ul);
47 
48  f = openfpm::math::round_big_2(7);
49  BOOST_REQUIRE_EQUAL(f,8ul);
50 
51  f = openfpm::math::round_big_2(21);
52  BOOST_REQUIRE_EQUAL(f,32ul);
53 
55 
57 
58  f = openfpm::math::pow(3,3);
59  BOOST_REQUIRE_EQUAL(f,27ul);
60 
61  f = openfpm::math::pow(4,2);
62  BOOST_REQUIRE_EQUAL(f,16ul);
63 
64  f = openfpm::math::pow(2,5);
65  BOOST_REQUIRE_EQUAL(f,32ul);
66 
68 
70 
71  f = openfpm::math::positive_modulo(-1,3);
72  BOOST_REQUIRE_EQUAL(f,2ul);
73 
74  f = openfpm::math::positive_modulo(-5,2);
75  BOOST_REQUIRE_EQUAL(f,1ul);
76 
77  f = openfpm::math::positive_modulo(-7,5);
78  BOOST_REQUIRE_EQUAL(f,3ul);
79 
81 
83 
84  float ff = openfpm::math::periodic(10.9,1.1,0.1);
85  BOOST_REQUIRE_CLOSE(ff,0.9,0.0001);
86 
87  ff = openfpm::math::periodic(0.0,1.1,0.1);
88  BOOST_REQUIRE_CLOSE(ff,1.0,0.0001);
89 
90  ff = openfpm::math::periodic(-7.0,1.1,0.1);
91  BOOST_REQUIRE_CLOSE(ff,1.0,0.0001);
92 
93  // in float representation 1.1 is a little bigger than 1.1
94  ff = openfpm::math::periodic(-10.9,1.1,0.1);
95  BOOST_REQUIRE_CLOSE(ff,1.1,0.0001);
96 
98 
100 
101  ff = openfpm::math::periodic(0.0,1.1,0.1);
102  BOOST_REQUIRE_CLOSE(ff,1.0,0.0001);
103 
104  ff = openfpm::math::periodic(1.2,1.1,0.1);
105  BOOST_REQUIRE_CLOSE(ff,0.2,0.0001);
106 
107  // in float representation 1.1 is a little bigger than 1.1
108  ff = openfpm::math::periodic(0.9,1.1,0.1);
109  BOOST_REQUIRE_CLOSE(ff,0.9,0.0001);
110 
112 }
113 
114 BOOST_AUTO_TEST_SUITE_END()
115 
116 #endif /* OPENFPM_DATA_SRC_UTIL_MATHUTIL_UNIT_TEST_HPP_ */