PageRenderTime 30ms CodeModel.GetById 15ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/unordered/test/unordered/assign_tests.cpp

http://hadesmem.googlecode.com/
C++ | 152 lines | 121 code | 28 blank | 3 comment | 4 complexity | 1afd195241ab437d19ad5cf5f3ebf7be MD5 | raw file
  1
  2// Copyright 2006-2009 Daniel James.
  3// Distributed under 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#include "../helpers/prefix.hpp"
  7
  8#include <boost/unordered_set.hpp>
  9#include <boost/unordered_map.hpp>
 10#include "../helpers/test.hpp"
 11#include "../objects/test.hpp"
 12#include "../helpers/random_values.hpp"
 13#include "../helpers/tracker.hpp"
 14#include "../helpers/equivalent.hpp"
 15
 16#include <iostream>
 17
 18namespace assign_tests {
 19
 20test::seed_t seed(96785);
 21
 22template <class T>
 23void assign_tests1(T*,
 24    test::random_generator generator = test::default_generator)
 25{
 26    BOOST_DEDUCED_TYPENAME T::hasher hf;
 27    BOOST_DEDUCED_TYPENAME T::key_equal eq;
 28
 29    std::cerr<<"assign_tests1.1\n";
 30    {
 31        T x;
 32        x = x;
 33        BOOST_TEST(x.empty());
 34        BOOST_TEST(test::equivalent(x.hash_function(), hf));
 35        BOOST_TEST(test::equivalent(x.key_eq(), eq));
 36    }
 37
 38    std::cerr<<"assign_tests1.2\n";
 39    {
 40        test::random_values<T> v(1000, generator);
 41        T x(v.begin(), v.end());
 42
 43        test::ordered<T> tracker = test::create_ordered(x);
 44        tracker.insert_range(v.begin(), v.end());
 45
 46        x = x;
 47        tracker.compare(x);
 48
 49        T y;
 50        y.max_load_factor(x.max_load_factor() / 20);
 51        y = x;
 52        tracker.compare(y);
 53        BOOST_TEST(x.max_load_factor() == y.max_load_factor());
 54    }
 55}
 56
 57template <class T>
 58void assign_tests2(T*,
 59    test::random_generator generator = test::default_generator)
 60{
 61    BOOST_DEDUCED_TYPENAME T::hasher hf1(1);
 62    BOOST_DEDUCED_TYPENAME T::hasher hf2(2);
 63    BOOST_DEDUCED_TYPENAME T::key_equal eq1(1);
 64    BOOST_DEDUCED_TYPENAME T::key_equal eq2(2);
 65    BOOST_DEDUCED_TYPENAME T::allocator_type al1(1);
 66    BOOST_DEDUCED_TYPENAME T::allocator_type al2(2);
 67
 68    std::cerr<<"assign_tests2.1\n";
 69    {
 70        test::random_values<T> v(1000, generator);
 71        T x1(v.begin(), v.end(), 0, hf1, eq1);
 72        T x2(0, hf2, eq2);
 73        x2 = x1;
 74        BOOST_TEST(test::equivalent(x2.hash_function(), hf1));
 75        BOOST_TEST(test::equivalent(x2.key_eq(), eq1));
 76        test::check_container(x2, v);
 77    }
 78
 79    std::cerr<<"assign_tests2.2\n";
 80    {
 81        test::random_values<T> v1(100, generator), v2(100, generator);
 82        T x1(v1.begin(), v1.end(), 0, hf1, eq1, al1);
 83        T x2(v2.begin(), v2.end(), 0, hf2, eq2, al2);
 84        x2 = x1;
 85        BOOST_TEST(test::equivalent(x2.hash_function(), hf1));
 86        BOOST_TEST(test::equivalent(x2.key_eq(), eq1));
 87        BOOST_TEST(test::equivalent(x2.get_allocator(), al2));
 88        test::check_container(x2, v1);
 89    }
 90}
 91
 92boost::unordered_set<test::object,
 93    test::hash, test::equal_to,
 94    test::allocator<test::object> >* test_set;
 95boost::unordered_multiset<test::object,
 96    test::hash, test::equal_to,
 97    test::allocator<test::object> >* test_multiset;
 98boost::unordered_map<test::object, test::object,
 99    test::hash, test::equal_to,
100    test::allocator<test::object> >* test_map;
101boost::unordered_multimap<test::object, test::object,
102    test::hash, test::equal_to,
103    test::allocator<test::object> >* test_multimap;
104
105using test::default_generator;
106using test::generate_collisions;
107
108UNORDERED_TEST(assign_tests1,
109    ((test_set)(test_multiset)(test_map)(test_multimap))
110    ((default_generator)(generate_collisions))
111)
112
113UNORDERED_TEST(assign_tests2,
114    ((test_set)(test_multiset)(test_map)(test_multimap))
115    ((default_generator)(generate_collisions))
116)
117
118#if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST)
119
120UNORDERED_AUTO_TEST(assign_default_initializer_list) {
121    std::cerr<<"Initializer List Tests\n";
122    std::initializer_list<std::pair<int const, int> > init;
123    boost::unordered_map<int, int> x1;
124    x1[25] = 3;
125    x1[16] = 10;
126    BOOST_TEST(!x1.empty());
127    x1 = init;
128    BOOST_TEST(x1.empty());
129}
130
131#endif
132
133#if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST) && \
134    !defined(BOOST_NO_INITIALIZER_LISTS)
135
136UNORDERED_AUTO_TEST(assign_initializer_list)
137{
138    std::cerr<<"Initializer List Tests\n";
139
140    boost::unordered_set<int> x;
141    x.insert(10);
142    x.insert(20);
143    x = { 1, 2, -10 };
144    BOOST_TEST(x.find(10) == x.end());
145    BOOST_TEST(x.find(-10) != x.end());
146}
147
148#endif
149
150}
151
152RUN_TESTS()