1 #ifndef BOOST_TEST_DIVIDE_HPP
2 #define BOOST_TEST_DIVIDE_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)
11 #include <boost/core/demangle.hpp>
13 #include <boost/safe_numerics/safe_integer.hpp>
14 #include <boost/safe_numerics/range_value.hpp>
16 template<class T1, class T2>
26 using result_type = decltype(t1 / v2);
28 << "safe<" << av1 << "> / " << av2 << " -> "
29 << boost::core::demangle(typeid(result_type).name()) << '\n';
31 boost::safe_numerics::is_safe<safe_t<T1> >::value,
35 boost::safe_numerics::is_safe<result_type>::value,
36 "Expression failed to return safe type"
40 // use auto to avoid checking assignment.
41 auto result = t1 / v2;
42 std::cout << make_result_display(result);
43 if(expected_result == 'x'){
44 std::cout << " *** failed to detect error in division" << std::endl;
48 std::cout << std::endl;
50 catch(const std::exception &){
51 if(expected_result == '.'){
52 std::cout << " *** erroneously detected error in division" << std::endl;
56 catch(const std::exception &){}
63 using result_type = decltype(v1 / t2);
65 << "safe<" << av1 << "> / " << av2 << " -> "
66 << boost::core::demangle(typeid(result_type).name()) << '\n';
69 boost::safe_numerics::is_safe<safe_t<T2> >::value,
73 boost::safe_numerics::is_safe<result_type>::value,
74 "Expression failed to return safe type"
77 // use auto to avoid checking assignment.
78 auto result = v1 / t2;
79 std::cout << make_result_display(result);
80 if(expected_result == 'x'){
81 std::cout << " *** failed to detect error in division " << std::endl;
85 std::cout << std::endl;
87 catch(const std::exception &){
88 if(expected_result == '.'){
89 std::cout << "*** erroneously detected error in division " << std::endl;
93 catch(const std::exception &){}
94 // assert(result == unsafe_result);
102 using result_type = decltype(t1 / t2);
104 << "testing safe<" << av1 << "> / safe<" << av2 << "> -> "
105 << boost::core::demangle(typeid(result_type).name()) << '\n';
108 boost::safe_numerics::is_safe<result_type>::value,
109 "Expression failed to return safe type"
113 // use auto to avoid checking assignment.
114 auto result = t1 / t2;
115 std::cout << make_result_display(result);
116 if(expected_result == 'x'){
117 std::cout << " *** failed to detect error in division" << std::endl;
121 std::cout << std::endl;
123 catch(const std::exception &){
124 if(expected_result == '.'){
125 std::cout << " *** erroneously detected error in division \\" << std::endl;
129 catch(const std::exception &){}
137 #endif // BOOST_TEST_DIVIDE