PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://hadesmem.googlecode.com/
C++ | 84 lines | 65 code | 16 blank | 3 comment | 34 complexity | fff666f016d4ac8d7e4c86aae7419106 MD5 | raw file
 1
 2// Copyright 2007-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
12#include <iostream>
13
14namespace insert_stable
15{
16    struct member {
17        int tag1_;
18        int tag2_;
19    
20        member() : tag1_(0), tag2_(0) {}
21        member(int t1, int t2) : tag1_(t1), tag2_(t2) {}
22    
23        friend bool operator==(member const& x, member const& y) {
24            return x.tag1_ == y.tag1_;
25        }
26    
27        friend bool operator!=(member const& x, member const& y) {
28            return x.tag1_ != y.tag1_;
29        }
30    };
31}
32
33#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
34namespace boost
35#else
36namespace insert_stable
37#endif
38{
39    std::size_t hash_value(insert_stable::member const& x) {
40        return static_cast<std::size_t>(x.tag1_);
41    }
42}
43
44UNORDERED_AUTO_TEST(stable_insert_test1) {
45    boost::unordered_multiset<insert_stable::member> x;
46
47    x.insert(insert_stable::member(1,1));
48    x.insert(insert_stable::member(1,2));
49    x.insert(insert_stable::member(1,3));
50
51    boost::unordered_multiset<insert_stable::member>::const_iterator
52        it = x.begin(), end = x.end();
53    BOOST_TEST(it != end);
54    if(it != end) { BOOST_TEST(it->tag2_ == 1); ++it; }
55    BOOST_TEST(it != end);
56    if(it != end) { BOOST_TEST(it->tag2_ == 2); ++it; }
57    BOOST_TEST(it != end);
58    if(it != end) { BOOST_TEST(it->tag2_ == 3); ++it; }
59    BOOST_TEST(it == end);
60}
61
62UNORDERED_AUTO_TEST(stable_insert_test2) {
63    boost::unordered_multimap<insert_stable::member, int> x;
64    typedef
65        boost::unordered_multimap<insert_stable::member, int>::const_iterator
66        iterator;
67
68    iterator it
69        = x.insert(x.end(), std::make_pair(insert_stable::member(1,1), 1));
70    it = x.insert(it, std::make_pair(insert_stable::member(1,2), 2));
71    it = x.insert(it, std::make_pair(insert_stable::member(1,3), 3));
72
73    it = x.begin();
74    iterator end = x.end();
75    BOOST_TEST(it != end);
76    if(it != end) { BOOST_TEST(it->first.tag2_ == 1 && it->second == 1); ++it; }
77    BOOST_TEST(it != end);
78    if(it != end) { BOOST_TEST(it->first.tag2_ == 2 && it->second == 2); ++it; }
79    BOOST_TEST(it != end);
80    if(it != end) { BOOST_TEST(it->first.tag2_ == 3 && it->second == 3); ++it; }
81    BOOST_TEST(it == end);
82}
83
84RUN_TESTS()