1 #ifndef BOOST_TEST_MODULUS_HPP
2 #define BOOST_TEST_MODULUS_HPP
4 // Copyright (c) 2015 Robert Ramey
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
12 #include <boost/safe_numerics/safe_integer.hpp>
13 #include <boost/safe_numerics/range_value.hpp>
15 template<class T1, class T2>
23 std::cout << "testing"<< std::endl;
26 using result_type = decltype(t1 % v2);
27 std::cout << "safe<" << av1 << "> % " << av2 << " -> ";
29 boost::safe_numerics::is_safe<safe_t<T1> >::value,
33 boost::safe_numerics::is_safe<result_type>::value,
34 "Expression failed to return safe type"
38 // use auto to avoid checking assignment.
39 auto result = t1 % v2;
40 std::cout << make_result_display(result);
41 if(expected_result == 'x'){
43 << " ! = "<< av1 << " % " << av2
44 << " failed to detect error in modulus"
49 std::cout << std::endl;
51 catch(const std::exception &){
52 if(expected_result == '.'){
54 << " == "<< av1 << " % " << av2
55 << " erroneously detected error in modulus"
60 catch(const std::exception &){}
67 using result_type = decltype(v1 % t2);
68 std::cout << av1 << " % " << "safe<" << av2 << "> -> ";
70 boost::safe_numerics::is_safe<safe_t<T2> >::value,
74 boost::safe_numerics::is_safe<result_type>::value,
75 "Expression failed to return safe type"
79 // use auto to avoid checking assignment.
80 auto result = v1 % t2;
81 std::cout << make_result_display(result);
82 if(expected_result =='x'){
84 << " ! = "<< av1 << " % " << av2
85 << " failed to detect error in modulus"
90 catch(const std::exception &){}
93 std::cout << std::endl;
95 catch(const std::exception &){
96 if(expected_result != 'x'){
98 << " == "<< av1 << " % " << av2
99 << " erroneously detected error in modulus"
104 catch(const std::exception &){}
112 using result_type = decltype(t1 + t2);
113 std::cout << "safe<" << av1 << "> % " << "safe<" << av2 << "> -> ";
115 boost::safe_numerics::is_safe<result_type>::value,
116 "Expression failed to return safe type"
120 // use auto to avoid checking assignment.
121 auto result = t1 % t2;
122 std::cout << make_result_display(result);
123 if(expected_result != '.'){
125 << " ! = "<< av1 << " % " << av2
126 << " failed to detect error in modulus"
131 catch(const std::exception &){}
134 std::cout << std::endl;
136 catch(const std::exception &){
137 if(expected_result != 'x'){
139 << " == "<< av1 << " % " << av2
140 << " erroneously detected error in modulus"
145 catch(const std::exception &){}
153 #endif // BOOST_TEST_MODULUS