2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CDSUNIT_MAP_TEST_MICHAEL_ITERABLE_MAP_HP_H
32 #define CDSUNIT_MAP_TEST_MICHAEL_ITERABLE_MAP_HP_H
34 #include "test_michael_iterable.h"
38 class michael_iterable_hp: public michael_iterable_map
40 typedef michael_iterable_map base_class;
46 // Precondition: map is empty
47 // Postcondition: map is empty
49 base_class::test( m );
51 EXPECT_TRUE( m.empty());
52 EXPECT_CONTAINER_SIZE( m, 0 );
54 typedef typename Map::value_type map_pair;
55 size_t const kkSize = base_class::kSize;
57 std::vector<key_type> arrKeys;
58 for ( int i = 0; i < static_cast<int>(kkSize); ++i )
59 arrKeys.push_back( key_type( i ));
60 shuffle( arrKeys.begin(), arrKeys.end());
62 std::vector< value_type > arrVals;
63 for ( size_t i = 0; i < kkSize; ++i ) {
65 val.nVal = static_cast<int>( i );
66 val.strVal = std::to_string( i );
67 arrVals.push_back( val );
70 for ( auto const& i : arrKeys )
71 EXPECT_TRUE( m.insert( i ) );
72 EXPECT_FALSE( m.empty() );
73 EXPECT_CONTAINER_SIZE( m, kkSize );
77 for ( auto it = m.begin(); it != m.end(); ++it ) {
78 EXPECT_EQ( it->second.nVal, 0 );
79 it->second.nVal = it->first.nKey * 2;
82 EXPECT_EQ( nCount, kkSize );
85 for ( auto it = m.cbegin(); it != m.cend(); ++it ) {
86 EXPECT_EQ( it->second.nVal, it->first.nKey * 2 );
89 EXPECT_EQ( nCount, kkSize );
92 typedef typename Map::guarded_ptr guarded_ptr;
95 for ( auto const& i : arrKeys ) {
96 value_type const& val = arrVals.at( i.nKey );
100 EXPECT_EQ( gp->first.nKey, i.nKey );
104 EXPECT_EQ( gp->first.nKey, i.nKey );
106 gp = m.get_with( other_item( i.nKey ), other_less());
108 EXPECT_EQ( gp->first.nKey, i.nKey );
110 switch ( i.nKey % 4 ) {
112 gp = m.extract( i.nKey );
118 gp = m.extract( val.strVal );
121 gp = m.extract_with( other_item( i.nKey ), other_less());
125 EXPECT_EQ( gp->first.nKey, i.nKey );
128 gp = m.get( i.nKey );
132 gp = m.get_with( other_item( i.nKey ), other_less() );
135 EXPECT_TRUE( m.empty() );
136 EXPECT_CONTAINER_SIZE( m, 0 );
140 } // namespace cds_test
142 #endif // #ifndef CDSUNIT_MAP_TEST_MICHAEL_ITERABLE_MAP_HP_H