|
Boost-Commit : |
From: john_at_[hidden]
Date: 2008-01-25 12:07:55
Author: johnmaddock
Date: 2008-01-25 12:07:54 EST (Fri, 25 Jan 2008)
New Revision: 42966
URL: http://svn.boost.org/trac/boost/changeset/42966
Log:
Added tests for integer conversion.
Text files modified:
sandbox/interval_math_toolkit/libs/numeric/interval/test/Jamfile.v2 | 5 ++-
sandbox/interval_math_toolkit/libs/numeric/interval/test/integer.cpp | 57 +++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 3 deletions(-)
Modified: sandbox/interval_math_toolkit/libs/numeric/interval/test/Jamfile.v2
==============================================================================
--- sandbox/interval_math_toolkit/libs/numeric/interval/test/Jamfile.v2 (original)
+++ sandbox/interval_math_toolkit/libs/numeric/interval/test/Jamfile.v2 2008-01-25 12:07:54 EST (Fri, 25 Jan 2008)
@@ -21,8 +21,6 @@
{
test-suite numeric/interval :
- [ compile libs/numeric/interval/test/integer.cpp ]
-
[ run libs/numeric/interval/test/add.cpp ]
[ run libs/numeric/interval/test/det.cpp ]
[ run libs/numeric/interval/test/fmod.cpp ]
@@ -45,5 +43,8 @@
../../../test/build//boost_test_exec_monitor/<link>static ]
[ run libs/numeric/interval/test/test_float.cpp
../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run libs/numeric/interval/test/integer.cpp
+ ../../../test/build//boost_test_exec_monitor/<link>static ]
;
}
+
Modified: sandbox/interval_math_toolkit/libs/numeric/interval/test/integer.cpp
==============================================================================
--- sandbox/interval_math_toolkit/libs/numeric/interval/test/integer.cpp (original)
+++ sandbox/interval_math_toolkit/libs/numeric/interval/test/integer.cpp 2008-01-25 12:07:54 EST (Fri, 25 Jan 2008)
@@ -10,15 +10,70 @@
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/ext/integer.hpp>
+#include <boost/numeric/interval/policies.hpp>
+#include <boost/test/test_tools.hpp>
+#include <boost/limits.hpp>
+#include <iostream>
#include "bugs.hpp"
typedef boost::numeric::interval<float> I;
-int main() {
+template <class I, class Int>
+void test_construct_from(I, Int, const char* name, const char* iname)
+{
+ std::cout << "Checking contruction of " << name << " from " << iname << std::endl;
+ typedef typename I::base_type value_type;
+ Int i = (std::numeric_limits<Int>::max)() / 2;
+ if((i & 1) == 0)
+ --i;
+ I inter(i);
+ BOOST_CHECK_PREDICATE(std::less_equal<value_type>(), (inter.lower())(static_cast<value_type>(i)));
+ BOOST_CHECK_PREDICATE(std::greater_equal<value_type>(), (inter.upper())(static_cast<value_type>(i)));
+ Int a = static_cast<Int>(inter.lower());
+ BOOST_CHECK_PREDICATE(std::less_equal<Int>(), (a)(i));
+ a = static_cast<Int>(inter.upper());
+ BOOST_CHECK_PREDICATE(std::greater_equal<Int>(), (a)(i));
+ BOOST_CHECK_PREDICATE(std::less_equal<value_type>(), (width(inter) / median(inter)) (std::numeric_limits<value_type>::epsilon()));
+ i = (std::numeric_limits<Int>::min)() / 2;
+ if((i & 1) == 0)
+ ++i;
+ inter = I(i);
+ BOOST_CHECK_PREDICATE(std::less_equal<value_type>(), (inter.lower())(static_cast<value_type>(i)));
+ BOOST_CHECK_PREDICATE(std::greater_equal<value_type>(), (inter.upper())(static_cast<value_type>(i)));
+ a = static_cast<Int>(inter.lower());
+ BOOST_CHECK_PREDICATE(std::less_equal<Int>(), (a)(i));
+ a = static_cast<Int>(inter.upper());
+ BOOST_CHECK_PREDICATE(std::greater_equal<Int>(), (a)(i));
+ if(median(inter) != 0)
+ BOOST_CHECK_PREDICATE(std::less_equal<value_type>(), (width(inter) / median(inter)) (std::numeric_limits<value_type>::epsilon()));
+}
+
+template <class I>
+void test_construct(I inter, const char* name)
+{
+ test_construct_from(inter, 0, name, "int");
+ test_construct_from(inter, 0u, name, "unsigned int");
+ test_construct_from(inter, 0L, name, "long");
+ test_construct_from(inter, 0uL, name, "unsigned long");
+#ifdef BOOST_HAS_LONG_LONG
+ test_construct_from(inter, 0LL, name, "long long");
+ test_construct_from(inter, 0uLL, name, "unsigned long long");
+#endif
+}
+
+int test_main(int, char *[]) {
I x, y;
x = 4 - (2 * y + 1) / 3;
# ifdef __BORLANDC__
::detail::ignore_warnings();
# endif
+
+ using namespace boost::numeric;
+ using namespace boost::numeric::interval_lib;
+
+ test_construct(interval<float, policies<rounded_arith_std<float>, checking_no_empty<float> > >(), "interval<float, policies<rounded_arith_std<float>, checking_no_empty<float> > >");
+ test_construct(interval<float, policies<rounded_arith_opp<float>, checking_no_empty<float> > >(), "interval<float, policies<rounded_arith_opp<float>, checking_no_empty<float> > >");
+ test_construct(interval<double, policies<rounded_arith_std<double>, checking_no_empty<double> > >(), "interval<double, policies<rounded_arith_std<double>, checking_no_empty<double> > >");
+ test_construct(interval<double, policies<rounded_arith_opp<double>, checking_no_empty<double> > >(), "interval<double, policies<rounded_arith_opp<double>, checking_no_empty<double> > >");
return 0;
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk