Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86500 - trunk/libs/serialization/test
From: ramey_at_[hidden]
Date: 2013-10-28 11:36:41


Author: ramey
Date: 2013-10-28 11:36:41 EDT (Mon, 28 Oct 2013)
New Revision: 86500
URL: http://svn.boost.org/trac/boost/changeset/86500

Log:
corrected # digits
corrected tests which compare floating point numbers to require max 1 digit difference

Text files modified:
   trunk/libs/serialization/test/A.cpp | 9 +++------
   trunk/libs/serialization/test/B.hpp | 7 ++++---
   trunk/libs/serialization/test/test_complex.cpp | 27 +++++++++++++++++----------
   trunk/libs/serialization/test/test_non_default_ctor.cpp | 13 +++++++------
   trunk/libs/serialization/test/test_non_intrusive.cpp | 13 +++++++------
   trunk/libs/serialization/test/test_simple_class.cpp | 16 +++-------------
   trunk/libs/serialization/test/test_traits_fail.cpp | 2 +-
   trunk/libs/serialization/test/test_variant.cpp | 7 ++++---
   8 files changed, 46 insertions(+), 48 deletions(-)

Modified: trunk/libs/serialization/test/A.cpp
==============================================================================
--- trunk/libs/serialization/test/A.cpp Mon Oct 28 11:34:58 2013 (r86499)
+++ trunk/libs/serialization/test/A.cpp 2013-10-28 11:36:41 EDT (Mon, 28 Oct 2013) (r86500)
@@ -12,6 +12,7 @@
 #include <cstdlib> // rand()
 #include <cmath> // fabs()
 #include <cstddef> // size_t
+#include <boost/math/special_functions/next.hpp>
 
 #include <boost/config.hpp>
 #if defined(BOOST_NO_STDC_NAMESPACE)
@@ -148,13 +149,9 @@
         return false;
     if(v != rhs.v)
         return false;
- if(w == 0 && std::fabs(rhs.w) > 2 * std::numeric_limits<float>::round_error())
+ if(std::abs( boost::math::float_distance(w, rhs.w)) > 1)
         return false;
- if(std::fabs(rhs.w/w - 1.0) > 2 * std::numeric_limits<float>::round_error())
- return false;
- if(x == 0 && std::fabs(rhs.x - x) > 2 * std::numeric_limits<double>::round_error())
- return false;
- if(std::fabs(rhs.x/x - 1.0) > 2 * std::numeric_limits<double>::round_error())
+ if(std::abs( boost::math::float_distance(x, rhs.x)) > 1)
         return false;
     if(0 != y.compare(rhs.y))
         return false;

Modified: trunk/libs/serialization/test/B.hpp
==============================================================================
--- trunk/libs/serialization/test/B.hpp Mon Oct 28 11:34:58 2013 (r86499)
+++ trunk/libs/serialization/test/B.hpp 2013-10-28 11:36:41 EDT (Mon, 28 Oct 2013) (r86500)
@@ -18,6 +18,7 @@
 
 #include <cstdlib> // for rand()
 #include <cmath>
+#include <boost/math/special_functions/next.hpp>
 
 #include <boost/config.hpp>
 #if defined(BOOST_NO_STDC_NAMESPACE)
@@ -105,9 +106,9 @@
         && s == rhs.s
         && t == rhs.t
         && u == rhs.u
- && v == rhs.v
- && std::fabs(w - rhs.w) <= std::numeric_limits<float>::round_error()
- && std::fabs(x - rhs.x) <= std::numeric_limits<float>::round_error()
+ && v == rhs.v
+ && std::abs( boost::math::float_distance(w, rhs.w)) < 2
+ && std::abs( boost::math::float_distance(x, rhs.x)) < 2
     ;
 }
 

Modified: trunk/libs/serialization/test/test_complex.cpp
==============================================================================
--- trunk/libs/serialization/test/test_complex.cpp Mon Oct 28 11:34:58 2013 (r86499)
+++ trunk/libs/serialization/test/test_complex.cpp 2013-10-28 11:36:41 EDT (Mon, 28 Oct 2013) (r86500)
@@ -15,9 +15,10 @@
 #include <cstdio> // remove
 #include <boost/config.hpp>
 #include <boost/detail/workaround.hpp>
-#include <boost/limits.hpp>
+#include <boost/math/special_functions/next.hpp>
 
 #if defined(BOOST_NO_STDC_NAMESPACE)
+#include <boost/limits.hpp>
 namespace std{
     using ::rand;
     using ::remove;
@@ -30,15 +31,15 @@
 }
 #endif
 
-#include <boost/config.hpp>
-#include <boost/limits.hpp>
-
 #include "test_tools.hpp"
+
 #include <boost/preprocessor/stringize.hpp>
 #include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
 
 #include <boost/serialization/complex.hpp>
 
+#include <iostream>
+
 int test_main( int /* argc */, char* /* argv */[] )
 {
     const char * testfile = boost::archive::tmpnam(NULL);
@@ -46,12 +47,12 @@
 
     // test array of objects
     std::complex<float> a(
- static_cast<float>(std::rand()),
- static_cast<float>(std::rand())
+ static_cast<float>(std::rand()) / static_cast<float>(std::rand()),
+ static_cast<float>(std::rand()) / static_cast<float>(std::rand())
     );
     std::complex<double> b(
- static_cast<double>(std::rand()),
- static_cast<double>(std::rand())
+ static_cast<double>(std::rand()) / static_cast<double>(std::rand()),
+ static_cast<double>(std::rand()) / static_cast<double>(std::rand())
     );
     {
         test_ostream os(testfile, TEST_STREAM_FLAGS);
@@ -68,8 +69,14 @@
         ia >> boost::serialization::make_nvp("adoublecomplex", b1);
     }
 
- BOOST_CHECK(std::abs(a-a1) <= (2 * std::numeric_limits<float>::round_error()));
- BOOST_CHECK(std::abs(b-b1) <= (2 * std::numeric_limits<double>::round_error()));
+ std::cerr << "a.real()-a1a.real() distance = " << std::abs( boost::math::float_distance(a.real(), a1.real())) << std::endl;
+ BOOST_CHECK(std::abs(boost::math::float_distance(a.real(), a1.real())) < 2);
+ std::cerr << "a.imag() - a1a.imag() distance = " << std::abs( boost::math::float_distance(a.imag(), a1.imag())) << std::endl;
+ BOOST_CHECK(std::abs(boost::math::float_distance(a.imag(), a1.imag())) < 2);
+ std::cerr << "b.real() - b1.real() distance = " << std::abs( boost::math::float_distance(b.real(), b1.real())) << std::endl;
+ BOOST_CHECK(std::abs(boost::math::float_distance(b.real(), b1.real())) < 2);
+ std::cerr << "b.imag() - b1.imag() distance = " << std::abs( boost::math::float_distance(b.imag(), b1.imag())) << std::endl;
+ BOOST_CHECK(std::abs(boost::math::float_distance(b.imag(), b1.imag())) < 2);
 
     std::remove(testfile);
     return EXIT_SUCCESS;

Modified: trunk/libs/serialization/test/test_non_default_ctor.cpp
==============================================================================
--- trunk/libs/serialization/test/test_non_default_ctor.cpp Mon Oct 28 11:34:58 2013 (r86499)
+++ trunk/libs/serialization/test/test_non_default_ctor.cpp 2013-10-28 11:36:41 EDT (Mon, 28 Oct 2013) (r86500)
@@ -20,6 +20,7 @@
 #include <boost/config.hpp>
 #include <boost/detail/workaround.hpp>
 #include <boost/limits.hpp>
+#include <boost/math/special_functions/next.hpp>
 
 #if defined(BOOST_NO_STDC_NAMESPACE)
 namespace std{
@@ -100,8 +101,8 @@
         && t == rhs.t
         && u == rhs.u
         && v == rhs.v
- && std::fabs(w - rhs.w) <= std::numeric_limits<float>::round_error()
- && std::fabs(x - rhs.x) <= std::numeric_limits<float>::round_error()
+ && std::abs( boost::math::float_distance(w, rhs.w)) < 2
+ && std::abs( boost::math::float_distance(x, rhs.x)) < 2
     ;
 }
 
@@ -115,10 +116,10 @@
         return t < rhs.u;
     if(! (v == rhs.v) )
         return t < rhs.v;
- if(! (std::fabs(w - rhs.w) < std::numeric_limits<float>::round_error() ) )
- return t < rhs.w;
- if(! (std::fabs(x - rhs.x) < std::numeric_limits<float>::round_error() ) )
- return t < rhs.x;
+ if(std::abs( boost::math::float_distance(w, rhs.w)) > 1)
+ return false;
+ if(std::abs( boost::math::float_distance(x, rhs.x)) > 1)
+ return false;
     return false;
 }
 

Modified: trunk/libs/serialization/test/test_non_intrusive.cpp
==============================================================================
--- trunk/libs/serialization/test/test_non_intrusive.cpp Mon Oct 28 11:34:58 2013 (r86499)
+++ trunk/libs/serialization/test/test_non_intrusive.cpp 2013-10-28 11:36:41 EDT (Mon, 28 Oct 2013) (r86500)
@@ -19,6 +19,7 @@
 #include <boost/config.hpp>
 #include <boost/detail/workaround.hpp>
 #include <boost/limits.hpp>
+#include <boost/math/special_functions/next.hpp>
 
 #if defined(BOOST_NO_STDC_NAMESPACE)
 namespace std{
@@ -68,8 +69,8 @@
         && t == rhs.t
         && u == rhs.u
         && v == rhs.v
- && std::fabs(w - rhs.w) <= std::numeric_limits<float>::round_error()
- && std::fabs(x - rhs.x) <= std::numeric_limits<float>::round_error()
+ && std::abs( boost::math::float_distance(w, rhs.w)) < 2
+ && std::abs( boost::math::float_distance(x, rhs.x)) < 2
     ;
 }
 
@@ -83,10 +84,10 @@
         return t < rhs.u;
     if(! (v == rhs.v) )
         return t < rhs.v;
- if(! (std::fabs(w - rhs.w) < std::numeric_limits<float>::round_error() ) )
- return t < rhs.w;
- if(! (std::fabs(x - rhs.x) < std::numeric_limits<float>::round_error() ) )
- return t < rhs.x;
+ if(std::abs( boost::math::float_distance(w, rhs.w)) > 1)
+ return false;
+ if(std::abs( boost::math::float_distance(x, rhs.x)) > 1)
+ return false;
     return false;
 }
 

Modified: trunk/libs/serialization/test/test_simple_class.cpp
==============================================================================
--- trunk/libs/serialization/test/test_simple_class.cpp Mon Oct 28 11:34:58 2013 (r86499)
+++ trunk/libs/serialization/test/test_simple_class.cpp 2013-10-28 11:36:41 EDT (Mon, 28 Oct 2013) (r86500)
@@ -14,6 +14,7 @@
 #include <cstdio> // remove
 #include <fstream>
 #include <cmath>
+#include <boost/math/special_functions/next.hpp>
 
 #include <boost/config.hpp>
 
@@ -50,19 +51,8 @@
     BOOST_CHECK_EQUAL(u, rhs.u);
     BOOST_CHECK_EQUAL(v, rhs.v);
     BOOST_CHECK_EQUAL(l, rhs.l);
- BOOST_CHECK(!(
- w == 0
- && std::fabs(rhs.w) > std::numeric_limits<float>::round_error()
- ));
- BOOST_CHECK(!(
- std::fabs(rhs.w/w - 1.0) > 2.0 * std::numeric_limits<float>::round_error()
- ));
- BOOST_CHECK(!(
- x == 0 && std::fabs(rhs.x - x) > 2.0 * std::numeric_limits<double>::round_error()
- ));
- BOOST_CHECK(!(
- std::fabs(rhs.x/x - 1.0) > 2.0 * std::numeric_limits<double>::round_error()
- ));
+ BOOST_CHECK(std::abs( boost::math::float_distance(w, rhs.w)) < 2);
+ BOOST_CHECK(std::abs( boost::math::float_distance(x, rhs.x)) < 2);
     BOOST_CHECK(!(0 != y.compare(rhs.y)));
     #ifndef BOOST_NO_STD_WSTRING
     BOOST_CHECK(!(0 != z.compare(rhs.z)));

Modified: trunk/libs/serialization/test/test_traits_fail.cpp
==============================================================================
--- trunk/libs/serialization/test/test_traits_fail.cpp Mon Oct 28 11:34:58 2013 (r86499)
+++ trunk/libs/serialization/test/test_traits_fail.cpp 2013-10-28 11:36:41 EDT (Mon, 28 Oct 2013) (r86500)
@@ -34,7 +34,7 @@
 int
 test_main( int /* argc */, char* /* argv */[] )
 {
- return boost::exit_failure;
+ return EXIT_SUCCESS;
 }
 
 // EOF

Modified: trunk/libs/serialization/test/test_variant.cpp
==============================================================================
--- trunk/libs/serialization/test/test_variant.cpp Mon Oct 28 11:34:58 2013 (r86499)
+++ trunk/libs/serialization/test/test_variant.cpp 2013-10-28 11:36:41 EDT (Mon, 28 Oct 2013) (r86500)
@@ -18,8 +18,9 @@
 #include <cstddef> // NULL
 #include <cstdio> // remove
 #include <fstream>
-#include <cmath> // for fabs()
 #include <boost/config.hpp>
+#include <cmath> // for fabs()
+#include <boost/math/special_functions/next.hpp>
 #if defined(BOOST_NO_STDC_NAMESPACE)
 namespace std{
     using ::remove;
@@ -77,11 +78,11 @@
 
     bool operator()( const float & lhs, const float & rhs ) const
     {
- return std::fabs(lhs- rhs) < std::numeric_limits<float>::round_error();
+ return std::abs( boost::math::float_distance(lhs, rhs)) < 2;
     }
     bool operator()( const double & lhs, const double & rhs ) const
     {
- return std::fabs(lhs - rhs) < std::numeric_limits<float>::round_error();
+ return std::abs( boost::math::float_distance(lhs, rhs)) < 2;
     }
 };
 


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