Update of /cvsroot/boost/boost/libs/functional/hash/test
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv6347

Modified Files:
        Jamfile Jamfile.v2 
Added Files:
        hash_complex_test.cpp 
Log Message:
Add a test for hashing complex numbers.


--- NEW FILE: hash_complex_test.cpp ---

//  (C) Copyright Daniel James 2005.
//  Use, modification and distribution are subject to the
//  Boost Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include "./config.hpp"

#ifdef TEST_EXTENSIONS
#  ifdef TEST_STD_INCLUDES
#    include <functional>
#  else
#    include <boost/functional/hash.hpp>
#  endif
#endif

#include <boost/detail/lightweight_test.hpp>

#ifdef TEST_EXTENSIONS

#include <complex>
#include <sstream>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/uniform_real.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/limits.hpp>

template <class T>
void generic_complex_tests(std::complex<T> v)
{
    HASH_NAMESPACE::hash<std::complex<T> > complex_hasher;

    BOOST_TEST(complex_hasher(v) == complex_hasher(v));

    HASH_NAMESPACE::hash<T> real_hasher;
    T real = v.real();
    T imag = v.imag();

    BOOST_TEST(real_hasher(real) == complex_hasher(std::complex<T>(real)));

    if(imag != 0 && real_hasher(real) == complex_hasher(v)) {
        std::ostringstream os;
        os<<"real_hasher("<<real<<") == complex_hasher("
            <<v.real()<<" + "<<v.imag()<<"i) == "
            <<real_hasher(real)<<" (This might not be a bug).";
        BOOST_ERROR(os.str().c_str());
    }
}

template <class Float>
void complex_float_tests(Float*)
{
    boost::mt19937 rng;
    boost::uniform_real<Float> uniform;
    boost::variate_generator<boost::mt19937&, boost::uniform_real<Float> >
        uniform_generator(rng, uniform);

    for(int i = 0; i < 100; ++i)
    {
        std::complex<Float> v(uniform_generator(), uniform_generator());
        generic_complex_tests(v);
    }
}

template <class Integer>
void complex_integral_tests(Integer*)
{
    boost::mt19937 rng;
    boost::uniform_int<Integer> uniform(
            (std::numeric_limits<Integer>::min)(),
            (std::numeric_limits<Integer>::max)());
    boost::variate_generator<boost::mt19937&, boost::uniform_int<Integer> >
        uniform_generator(rng, uniform);

    for(int i = 0; i < 100; ++i)
    {
        std::complex<Integer>v(uniform_generator(), uniform_generator());
        generic_complex_tests(v);
    }
}

int main()
{
    complex_float_tests((float*) 0);
    complex_float_tests((double*) 0);
    complex_float_tests((long double*) 0);
    complex_integral_tests((short*) 0);
    complex_integral_tests((int*) 0);
    complex_integral_tests((long*) 0);
    complex_integral_tests((unsigned short*) 0);
    complex_integral_tests((unsigned int*) 0);
    complex_integral_tests((unsigned long*) 0);
}

#endif

Index: Jamfile
===================================================================
RCS file: /cvsroot/boost/boost/libs/functional/hash/test/Jamfile,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- Jamfile     18 Mar 2006 15:49:21 -0000      1.23
+++ Jamfile     6 Jun 2006 20:52:28 -0000       1.24
@@ -39,6 +39,7 @@
             [ hash-test hash_deque_test ]
             [ hash-test hash_set_test ]
             [ hash-test hash_map_test ]
+            [ hash-test hash_complex_test ]
             [ hash-test link_test link_test_2 ]
             [ hash-test link_ext_test link_no_ext_test ]
             [ run container_fwd_test.cpp : : : <include>$(BOOST_ROOT) ]

Index: Jamfile.v2
===================================================================
RCS file: /cvsroot/boost/boost/libs/functional/hash/test/Jamfile.v2,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- Jamfile.v2  18 Mar 2006 15:49:21 -0000      1.18
+++ Jamfile.v2  6 Jun 2006 20:52:28 -0000       1.19
@@ -30,6 +30,7 @@
         [ run hash_deque_test.cpp ]
         [ run hash_set_test.cpp ]
         [ run hash_map_test.cpp ]
+        [ run hash_complex_test.cpp ]
         [ run link_test.cpp link_test_2.cpp ]
         [ run link_ext_test.cpp link_no_ext_test.cpp ]
         [ run container_fwd_test.cpp ]



_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to