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 // clang-format off
7 #include "../helpers/prefix.hpp"
8 #include <boost/unordered_set.hpp>
9 #include <boost/unordered_map.hpp>
10 #include "../helpers/postfix.hpp"
11 // clang-format on
12 
13 #include "../helpers/test.hpp"
14 #include <algorithm>
15 #include <map>
16 #include "../helpers/list.hpp"
17 #include "../helpers/tracker.hpp"
18 #include "../helpers/invariants.hpp"
19 
20 template <class Container, class Iterator>
test_equal_insertion(Iterator begin,Iterator end)21 void test_equal_insertion(Iterator begin, Iterator end)
22 {
23   typedef test::ordered<Container> tracker;
24 
25   Container x1;
26   tracker x2 = test::create_ordered(x1);
27 
28   for (Iterator it = begin; it != end; ++it) {
29     x1.insert(*it);
30     x2.insert(*it);
31     x2.compare_key(x1, *it);
32   }
33 
34   x2.compare(x1);
35   test::check_equivalent_keys(x1);
36 }
37 
UNORDERED_AUTO_TEST(set_tests)38 UNORDERED_AUTO_TEST (set_tests) {
39   int values[][5] = {{1}, {54, 23}, {-13, 65}, {77, 77}, {986, 25, 986}};
40 
41   typedef boost::unordered_set<int> set;
42   typedef boost::unordered_multiset<int> multiset;
43 
44   test_equal_insertion<set>(values[0], values[0] + 1);
45   test_equal_insertion<set>(values[1], values[1] + 2);
46   test_equal_insertion<set>(values[2], values[2] + 2);
47   test_equal_insertion<set>(values[3], values[3] + 2);
48   test_equal_insertion<set>(values[4], values[4] + 3);
49 
50   test_equal_insertion<multiset>(values[0], values[0] + 1);
51   test_equal_insertion<multiset>(values[1], values[1] + 2);
52   test_equal_insertion<multiset>(values[2], values[2] + 2);
53   test_equal_insertion<multiset>(values[3], values[3] + 2);
54   test_equal_insertion<multiset>(values[4], values[4] + 3);
55 }
56 
UNORDERED_AUTO_TEST(map_tests)57 UNORDERED_AUTO_TEST (map_tests) {
58   typedef test::list<std::pair<int const, int> > values_type;
59   values_type v[5];
60   v[0].push_back(std::pair<int const, int>(1, 1));
61   v[1].push_back(std::pair<int const, int>(28, 34));
62   v[1].push_back(std::pair<int const, int>(16, 58));
63   v[1].push_back(std::pair<int const, int>(-124, 62));
64   v[2].push_back(std::pair<int const, int>(432, 12));
65   v[2].push_back(std::pair<int const, int>(9, 13));
66   v[2].push_back(std::pair<int const, int>(432, 24));
67 
68   for (int i = 0; i < 5; ++i)
69     test_equal_insertion<boost::unordered_map<int, int> >(
70       v[i].begin(), v[i].end());
71 
72   for (int i2 = 0; i2 < 5; ++i2)
73     test_equal_insertion<boost::unordered_multimap<int, int> >(
74       v[i2].begin(), v[i2].end());
75 }
76 
77 RUN_TESTS()
78