1 | /* |
2 | * util_num_unit_tests.hpp |
3 | * |
4 | * Created on: Oct 23, 2015 |
5 | * Author: i-bird |
6 | */ |
7 | |
8 | #ifndef OPENFPM_NUMERICS_SRC_UTIL_UTIL_NUM_UNIT_TESTS_HPP_ |
9 | #define OPENFPM_NUMERICS_SRC_UTIL_UTIL_NUM_UNIT_TESTS_HPP_ |
10 | |
11 | #include "util_num.hpp" |
12 | |
13 | //! [Constant fields struct definition] |
14 | |
15 | //! define a constant field |
16 | struct anyname_field |
17 | { |
18 | //! define that is a constant field |
19 | typedef void const_field; |
20 | |
21 | //! Evaluate the constant field (in this case always return 1.0) |
22 | float val() {return 1.0;} |
23 | }; |
24 | |
25 | //! define a non-constant (in space) field |
26 | struct anyname_field_with_pos |
27 | { |
28 | //! It define that is a constant field |
29 | typedef void const_field; |
30 | |
31 | //! It define that is not constant in space |
32 | typedef void with_position; |
33 | |
34 | //! Evaluate the field in one point |
35 | float val_pos(grid_key_dx<2> & pos) {return 1.0;} |
36 | }; |
37 | |
38 | //! stub field |
39 | struct no_field |
40 | { |
41 | }; |
42 | |
43 | //! [Constant fields struct definition] |
44 | |
45 | //! [Is on test struct definition] |
46 | |
47 | //! define that we are on testing mode |
48 | struct on_test |
49 | { |
50 | //! specify testing mode |
51 | typedef void testing; |
52 | }; |
53 | |
54 | //! Not on testing mode |
55 | struct not_on_test |
56 | { |
57 | }; |
58 | |
59 | //! [Is on test struct definition] |
60 | |
61 | BOOST_AUTO_TEST_SUITE( util_num_suite ) |
62 | |
63 | BOOST_AUTO_TEST_CASE( util_num ) |
64 | { |
65 | //! [Usage of is_const_field] |
66 | |
67 | bool ret = is_const_field<anyname_field>::value; |
68 | BOOST_REQUIRE_EQUAL(ret,true); |
69 | |
70 | ret = is_const_field<no_field>::value; |
71 | BOOST_REQUIRE_EQUAL(ret,false); |
72 | |
73 | //! [Usage of is_const_field] |
74 | |
75 | //! [Usage of has_val_pos] |
76 | |
77 | ret = is_const_field<anyname_field_with_pos>::value; |
78 | BOOST_REQUIRE_EQUAL(ret,true); |
79 | |
80 | ret = is_const_field<no_field>::value; |
81 | BOOST_REQUIRE_EQUAL(ret,false); |
82 | |
83 | //! [Usage of has_val_pos] |
84 | |
85 | //! [Usage of is_testing] |
86 | |
87 | ret = is_testing<on_test>::value; |
88 | BOOST_REQUIRE_EQUAL(ret,true); |
89 | |
90 | ret = is_testing<not_on_test>::value; |
91 | BOOST_REQUIRE_EQUAL(ret,false); |
92 | |
93 | //! [Usage of is_testing] |
94 | |
95 | //! [Usage of stub_or_real] |
96 | |
97 | ret = std::is_same<stub_or_real<on_test,2,float,CartDecomposition<2,float>>::type, grid_dist_testing<2>>::value ; |
98 | BOOST_REQUIRE_EQUAL(ret,true); |
99 | |
100 | ret = std::is_same<stub_or_real<not_on_test,2,float,CartDecomposition<2,float>>::type, grid_dist_id<2,float,aggregate<size_t>,CartDecomposition<2,float>> >::value; |
101 | BOOST_REQUIRE_EQUAL(ret,true); |
102 | |
103 | //! [Usage of stub_or_real] |
104 | } |
105 | |
106 | BOOST_AUTO_TEST_SUITE_END() |
107 | |
108 | #endif /* OPENFPM_NUMERICS_SRC_UTIL_UTIL_NUM_UNIT_TESTS_HPP_ */ |
109 | |