Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/functional/hash/test/hash_sequence_test.hpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.1 KB
Line 
1
2//  Copyright Daniel James 2005-2006. Use, modification, and distribution are
3//  subject to the Boost Software License, Version 1.0. (See accompanying
4//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#if !defined(CONTAINER_TYPE)
7#error "CONTAINER_TYPE not defined"
8#else
9
10#include <boost/preprocessor/cat.hpp>
11
12namespace BOOST_PP_CAT(CONTAINER_TYPE, _tests)
13{
14    template <class T>
15    void integer_tests(T* = 0)
16    {
17        const int number_of_containers = 11;
18        T containers[number_of_containers];
19
20        for(int i = 0; i < 5; ++i) {
21            for(int j = 0; j < i; ++j)
22                containers[i].push_back(0);
23        }
24
25        containers[5].push_back(1);
26        containers[6].push_back(1);
27        containers[6].push_back(1);
28        containers[7].push_back(-1);
29        containers[8].push_back(-1);
30        containers[8].push_back(-1);
31        containers[9].push_back(1);
32        containers[9].push_back(-1);
33        containers[10].push_back(-1);
34        containers[10].push_back(1);
35
36        HASH_NAMESPACE::hash<T> hasher;
37
38        for(int i2 = 0; i2 < number_of_containers; ++i2) {
39            BOOST_TEST(hasher(containers[i2]) == hasher(containers[i2]));
40
41            BOOST_TEST(hasher(containers[i2]) ==
42                    HASH_NAMESPACE::hash_value(containers[i2]));
43
44            BOOST_TEST(hasher(containers[i2])
45                    == HASH_NAMESPACE::hash_range(
46                        containers[i2].begin(), containers[i2].end()));
47
48            for(int j2 = i2 + 1; j2 < number_of_containers; ++j2) {
49                BOOST_TEST(
50                        (containers[i2] == containers[j2]) ==
51                        (hasher(containers[i2]) == hasher(containers[j2]))
52                        );
53            }
54        }
55    }
56
57    void BOOST_PP_CAT(CONTAINER_TYPE, _hash_integer_tests())
58    {
59        integer_tests((CONTAINER_TYPE<char>*) 0);
60        integer_tests((CONTAINER_TYPE<int>*) 0);
61        integer_tests((CONTAINER_TYPE<unsigned long>*) 0);
62        integer_tests((CONTAINER_TYPE<double>*) 0);
63    }
64}
65
66#undef CONTAINER_TYPE
67#endif
Note: See TracBrowser for help on using the repository browser.