Files
boost_unordered/test/unordered/equivalent_keys_tests.cpp

80 lines
2.6 KiB
C++
Raw Normal View History

// Copyright 2006-2009 Daniel James.
// Distributed under 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 <boost/unordered_set.hpp>
#include <boost/unordered_map.hpp>
#include "../helpers/test.hpp"
#include <algorithm>
#include <map>
Merge in support for equality operators for the unordered containers and hopefully better cross-platform support. Merged revisions 44778-44835,44837-44918 via svnmerge from https://svn.boost.org/svn/boost/branches/unordered/trunk ........ r44778 | danieljames | 2008-04-26 17:15:44 +0100 (Sat, 26 Apr 2008) | 2 lines Remove a trailing comma. ........ r44779 | danieljames | 2008-04-26 17:23:51 +0100 (Sat, 26 Apr 2008) | 1 line Merge in support for equality operators. ........ r44780 | danieljames | 2008-04-26 17:28:44 +0100 (Sat, 26 Apr 2008) | 1 line Use my own list container to avoid working around STL container bugs. ........ r44833 | danieljames | 2008-04-28 08:03:43 +0100 (Mon, 28 Apr 2008) | 1 line Better equality tests. ........ r44834 | danieljames | 2008-04-28 08:04:03 +0100 (Mon, 28 Apr 2008) | 1 line Remove a superfluous check. ........ r44835 | danieljames | 2008-04-28 08:04:21 +0100 (Mon, 28 Apr 2008) | 1 line Add equality reference documentation. ........ r44916 | danieljames | 2008-04-30 08:16:52 +0100 (Wed, 30 Apr 2008) | 1 line New version of list.hpp ........ r44917 | danieljames | 2008-04-30 08:18:31 +0100 (Wed, 30 Apr 2008) | 1 line Support compilers without ADL in the compile tests. ........ r44918 | danieljames | 2008-04-30 08:25:20 +0100 (Wed, 30 Apr 2008) | 7 lines Change the typedef of buffered functions as it was confusing MSVC 6.5 get_allocator wasn't compiling when the allocator workaround is used because it couldn't cast from the wrapped allocator to an allocator of another type. So use value_alloc_ when it's available (it's only unavailable on compilers with C++0x support, which don't require the workaround). ........ [SVN r44919]
2008-04-30 07:57:04 +00:00
#include "../helpers/list.hpp"
#include "../helpers/tracker.hpp"
#include "../helpers/invariants.hpp"
#include <iostream>
template <class Container, class Iterator>
void test_equal_insertion(Iterator begin, Iterator end)
{
typedef test::ordered<Container> tracker;
Container x1;
tracker x2 = test::create_ordered(x1);
for(Iterator it = begin; it != end; ++it) {
x1.insert(*it);
x2.insert(*it);
x2.compare_key(x1, *it);
}
x2.compare(x1);
test::check_equivalent_keys(x1);
}
UNORDERED_AUTO_TEST(set_tests)
{
int values[][5] = {
{1},
{54, 23},
{-13, 65},
{77, 77},
{986, 25, 986}
};
test_equal_insertion<boost::unordered_set<int> >(values[0], values[0] + 1);
test_equal_insertion<boost::unordered_set<int> >(values[1], values[1] + 2);
test_equal_insertion<boost::unordered_set<int> >(values[2], values[2] + 2);
test_equal_insertion<boost::unordered_set<int> >(values[3], values[3] + 2);
test_equal_insertion<boost::unordered_set<int> >(values[4], values[4] + 3);
test_equal_insertion<boost::unordered_multiset<int> >(values[0], values[0] + 1);
test_equal_insertion<boost::unordered_multiset<int> >(values[1], values[1] + 2);
test_equal_insertion<boost::unordered_multiset<int> >(values[2], values[2] + 2);
test_equal_insertion<boost::unordered_multiset<int> >(values[3], values[3] + 2);
test_equal_insertion<boost::unordered_multiset<int> >(values[4], values[4] + 3);
}
UNORDERED_AUTO_TEST(map_tests)
{
Merge in support for equality operators for the unordered containers and hopefully better cross-platform support. Merged revisions 44778-44835,44837-44918 via svnmerge from https://svn.boost.org/svn/boost/branches/unordered/trunk ........ r44778 | danieljames | 2008-04-26 17:15:44 +0100 (Sat, 26 Apr 2008) | 2 lines Remove a trailing comma. ........ r44779 | danieljames | 2008-04-26 17:23:51 +0100 (Sat, 26 Apr 2008) | 1 line Merge in support for equality operators. ........ r44780 | danieljames | 2008-04-26 17:28:44 +0100 (Sat, 26 Apr 2008) | 1 line Use my own list container to avoid working around STL container bugs. ........ r44833 | danieljames | 2008-04-28 08:03:43 +0100 (Mon, 28 Apr 2008) | 1 line Better equality tests. ........ r44834 | danieljames | 2008-04-28 08:04:03 +0100 (Mon, 28 Apr 2008) | 1 line Remove a superfluous check. ........ r44835 | danieljames | 2008-04-28 08:04:21 +0100 (Mon, 28 Apr 2008) | 1 line Add equality reference documentation. ........ r44916 | danieljames | 2008-04-30 08:16:52 +0100 (Wed, 30 Apr 2008) | 1 line New version of list.hpp ........ r44917 | danieljames | 2008-04-30 08:18:31 +0100 (Wed, 30 Apr 2008) | 1 line Support compilers without ADL in the compile tests. ........ r44918 | danieljames | 2008-04-30 08:25:20 +0100 (Wed, 30 Apr 2008) | 7 lines Change the typedef of buffered functions as it was confusing MSVC 6.5 get_allocator wasn't compiling when the allocator workaround is used because it couldn't cast from the wrapped allocator to an allocator of another type. So use value_alloc_ when it's available (it's only unavailable on compilers with C++0x support, which don't require the workaround). ........ [SVN r44919]
2008-04-30 07:57:04 +00:00
typedef test::list<std::pair<int const, int> > values_type;
values_type v[5];
v[0].push_back(std::pair<int const, int>(1,1));
v[1].push_back(std::pair<int const, int>(28,34));
v[1].push_back(std::pair<int const, int>(16,58));
v[1].push_back(std::pair<int const, int>(-124, 62));
v[2].push_back(std::pair<int const, int>(432,12));
v[2].push_back(std::pair<int const, int>(9,13));
v[2].push_back(std::pair<int const, int>(432,24));
for(int i = 0; i < 5; ++i)
test_equal_insertion<boost::unordered_map<int, int> >(
v[i].begin(), v[i].end());
for(int i2 = 0; i2 < 5; ++i2)
test_equal_insertion<boost::unordered_multimap<int, int> >(
v[i2].begin(), v[i2].end());
}
RUN_TESTS()