From 7561e4d35339e42b8c8e5aa6cec96192aa027e6f Mon Sep 17 00:00:00 2001 From: khizmax Date: Tue, 15 Sep 2015 23:54:48 +0300 Subject: [PATCH] Removed deprecated functions ensure() and find(key) from map unit tests --- tests/test-hdr/map/hdr_cuckoo_map.h | 54 ++++---- tests/test-hdr/map/hdr_map.h | 157 ++++++++++++---------- tests/test-hdr/map/hdr_skiplist_map.h | 55 ++++---- tests/test-hdr/map/hdr_skiplist_map_rcu.h | 6 +- tests/test-hdr/map/hdr_striped_map.h | 107 ++++++++------- 5 files changed, 203 insertions(+), 176 deletions(-) diff --git a/tests/test-hdr/map/hdr_cuckoo_map.h b/tests/test-hdr/map/hdr_cuckoo_map.h index d2429118..fb970997 100644 --- a/tests/test-hdr/map/hdr_cuckoo_map.h +++ b/tests/test-hdr/map/hdr_cuckoo_map.h @@ -120,7 +120,7 @@ namespace map { item.second.m_val = item.first * 3; } - // ensure ftor + // update() ftor void operator()( bool bNew, pair_type& item ) { if ( bNew ) @@ -212,49 +212,53 @@ namespace map { template void test_int_with( Map& m ) { - std::pair ensureResult; + std::pair updateResult; typedef typename std::conditional< Map::c_isSorted, less, equal >::type predicate; // insert CPPUNIT_ASSERT( m.empty() ); CPPUNIT_ASSERT( check_size( m, 0 )); - CPPUNIT_ASSERT( !m.find(25) ); + CPPUNIT_ASSERT( !m.contains(25) ); CPPUNIT_ASSERT( m.insert( 25 ) ) ; // value = 0 - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 1 )); - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( !m.insert( 25 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 1 )); - CPPUNIT_ASSERT( !m.find_with(10, predicate()) ); + CPPUNIT_ASSERT( !m.contains(10, predicate()) ); CPPUNIT_ASSERT( m.insert( 10, 10 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 2 )); - CPPUNIT_ASSERT( m.find_with(10, predicate()) ); + CPPUNIT_ASSERT( m.contains(10, predicate()) ); CPPUNIT_ASSERT( !m.insert( 10, 20 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 2 )); - CPPUNIT_ASSERT( !m.find(30) ); + CPPUNIT_ASSERT( !m.contains(30) ); CPPUNIT_ASSERT( m.insert_with( 30, insert_functor() ) ) ; // value = 90 CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( m.find(30) ); + CPPUNIT_ASSERT( m.contains(30) ); CPPUNIT_ASSERT( !m.insert_with( 10, insert_functor() ) ); CPPUNIT_ASSERT( !m.insert_with( 25, insert_functor() ) ); CPPUNIT_ASSERT( !m.insert_with( 30, insert_functor() ) ); - // ensure (new key) - CPPUNIT_ASSERT( !m.find(27) ); - ensureResult = m.ensure( 27, insert_functor() ) ; // value = 54 - CPPUNIT_ASSERT( ensureResult.first ); - CPPUNIT_ASSERT( ensureResult.second ); - CPPUNIT_ASSERT( m.find(27) ); + // update (new key) + CPPUNIT_ASSERT( !m.contains(27) ); + updateResult = m.update(27, insert_functor(), false); + CPPUNIT_ASSERT(!updateResult.first); + CPPUNIT_ASSERT(!updateResult.second); + CPPUNIT_ASSERT(!m.contains(27)); + updateResult = m.update( 27, insert_functor() ) ; // value = 54 + CPPUNIT_ASSERT( updateResult.first ); + CPPUNIT_ASSERT( updateResult.second ); + CPPUNIT_ASSERT( m.contains(27) ); // find test check_value chk(10); @@ -266,39 +270,39 @@ namespace map { chk.m_nExpected = 54; CPPUNIT_ASSERT( m.find( 27, std::ref(chk) )); - ensureResult = m.ensure( 10, insert_functor() ) ; // value = 50 - CPPUNIT_ASSERT( ensureResult.first ); - CPPUNIT_ASSERT( !ensureResult.second ); + updateResult = m.update( 10, insert_functor() ) ; // value = 50 + CPPUNIT_ASSERT( updateResult.first ); + CPPUNIT_ASSERT( !updateResult.second ); chk.m_nExpected = 50; CPPUNIT_ASSERT( m.find( 10, std::ref(chk) )); // erase test - CPPUNIT_ASSERT( !m.find(100) ); + CPPUNIT_ASSERT( !m.contains(100) ); CPPUNIT_ASSERT( !m.erase( 100 )) ; // not found - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( check_size( m, 4 )); CPPUNIT_ASSERT( m.erase( 25 )); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( !m.find(25) ); + CPPUNIT_ASSERT( !m.contains(25) ); CPPUNIT_ASSERT( !m.erase( 25 )); - CPPUNIT_ASSERT( !m.find(258) ); + CPPUNIT_ASSERT( !m.contains(258) ); CPPUNIT_ASSERT( m.insert(258)) CPPUNIT_ASSERT( check_size( m, 4 )); - CPPUNIT_ASSERT( m.find_with(258, predicate()) ); + CPPUNIT_ASSERT( m.contains(258, predicate()) ); CPPUNIT_ASSERT( m.erase_with( 258, predicate() )); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( !m.find(258) ); + CPPUNIT_ASSERT( !m.contains(258) ); CPPUNIT_ASSERT( !m.erase_with( 258, predicate() )); int nVal; extract_functor ext; ext.m_pVal = &nVal; - CPPUNIT_ASSERT( !m.find(29) ); + CPPUNIT_ASSERT( !m.contains(29) ); CPPUNIT_ASSERT( m.insert(29, 290)) CPPUNIT_ASSERT( m.erase_with( 29, predicate(), std::ref(ext))); CPPUNIT_ASSERT( !m.empty() ); diff --git a/tests/test-hdr/map/hdr_map.h b/tests/test-hdr/map/hdr_map.h index e5681373..c5624985 100644 --- a/tests/test-hdr/map/hdr_map.h +++ b/tests/test-hdr/map/hdr_map.h @@ -127,7 +127,7 @@ namespace map { item.second.m_val = item.first * 3; } - // ensure ftor + // update ftor void operator()( bool bNew, pair_type& item ) { if ( bNew ) @@ -442,48 +442,53 @@ namespace map { template void test_int_with( Map& m ) { - std::pair ensureResult; + std::pair updateResult; // insert CPPUNIT_ASSERT( m.empty() ); CPPUNIT_ASSERT( check_size( m, 0 )); - CPPUNIT_ASSERT( !m.find(25) ); + CPPUNIT_ASSERT( !m.contains(25) ); CPPUNIT_ASSERT( m.insert( 25 ) ) ; // value = 0 - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 1 )); - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( !m.insert( 25 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 1 )); - CPPUNIT_ASSERT( !m.find_with(10, less()) ); + CPPUNIT_ASSERT( !m.contains(10, less()) ); CPPUNIT_ASSERT( m.insert( 10, 10 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 2 )); - CPPUNIT_ASSERT( m.find_with(10, less()) ); + CPPUNIT_ASSERT( m.contains(10, less()) ); CPPUNIT_ASSERT( !m.insert( 10, 20 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 2 )); - CPPUNIT_ASSERT( !m.find(30) ); + CPPUNIT_ASSERT( !m.contains(30) ); CPPUNIT_ASSERT( m.insert_with( 30, insert_functor() ) ) ; // value = 90 CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( m.find(30) ); + CPPUNIT_ASSERT( m.contains(30) ); CPPUNIT_ASSERT( !m.insert_with( 10, insert_functor() ) ); CPPUNIT_ASSERT( !m.insert_with( 25, insert_functor() ) ); CPPUNIT_ASSERT( !m.insert_with( 30, insert_functor() ) ); - // ensure (new key) - CPPUNIT_ASSERT( !m.find(27) ); - ensureResult = m.ensure( 27, insert_functor() ) ; // value = 54 - CPPUNIT_ASSERT( ensureResult.first ); - CPPUNIT_ASSERT( ensureResult.second ); - CPPUNIT_ASSERT( m.find(27) ); + // update (new key) + CPPUNIT_ASSERT( !m.contains(27) ); + updateResult = m.update(27, insert_functor(), false); + CPPUNIT_ASSERT(!updateResult.first); + CPPUNIT_ASSERT(!updateResult.second); + CPPUNIT_ASSERT(!m.contains(27)); + + updateResult = m.update( 27, insert_functor() ) ; // value = 54 + CPPUNIT_ASSERT( updateResult.first ); + CPPUNIT_ASSERT( updateResult.second ); + CPPUNIT_ASSERT( m.contains(27) ); // find test check_value chk(10); @@ -495,39 +500,39 @@ namespace map { chk.m_nExpected = 54; CPPUNIT_ASSERT( m.find( 27, std::ref( chk ) ) ); - ensureResult = m.ensure( 10, insert_functor() ) ; // value = 50 - CPPUNIT_ASSERT( ensureResult.first ); - CPPUNIT_ASSERT( !ensureResult.second ); + updateResult = m.update( 10, insert_functor() ) ; // value = 50 + CPPUNIT_ASSERT( updateResult.first ); + CPPUNIT_ASSERT( !updateResult.second ); chk.m_nExpected = 50; CPPUNIT_ASSERT( m.find( 10, std::ref( chk ) ) ); // erase test - CPPUNIT_ASSERT( !m.find(100) ); + CPPUNIT_ASSERT( !m.contains(100) ); CPPUNIT_ASSERT( !m.erase( 100 )) ; // not found - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( check_size( m, 4 )); CPPUNIT_ASSERT( m.erase( 25 )); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( !m.find(25) ); + CPPUNIT_ASSERT( !m.contains(25) ); CPPUNIT_ASSERT( !m.erase( 25 )); - CPPUNIT_ASSERT( !m.find(258) ); + CPPUNIT_ASSERT( !m.contains(258) ); CPPUNIT_ASSERT( m.insert(258)) CPPUNIT_ASSERT( check_size( m, 4 )); - CPPUNIT_ASSERT( m.find_with(258, less()) ); + CPPUNIT_ASSERT( m.contains(258, less()) ); CPPUNIT_ASSERT( m.erase_with( 258, less() )); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( !m.find(258) ); + CPPUNIT_ASSERT( !m.contains(258) ); CPPUNIT_ASSERT( !m.erase_with( 258, less() )); int nVal; extract_functor ext; ext.m_pVal = &nVal; - CPPUNIT_ASSERT( !m.find(29) ); + CPPUNIT_ASSERT( !m.contains(29) ); CPPUNIT_ASSERT( m.insert(29, 290)); CPPUNIT_ASSERT( check_size( m, 4 )); CPPUNIT_ASSERT( m.erase_with( 29, less(), std::ref( ext ) ) ); @@ -589,30 +594,30 @@ namespace map { CPPUNIT_ASSERT( m.empty() ); CPPUNIT_ASSERT( check_size( m, 0 )); - CPPUNIT_ASSERT( m.find(10) == m.end() ); + CPPUNIT_ASSERT( m.contains(10) == m.end() ); iterator it = m.insert( 10 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 1 )); - CPPUNIT_ASSERT( m.find(10) == it ); + CPPUNIT_ASSERT( m.contains(10) == it ); CPPUNIT_ASSERT( it->first == 10 ); CPPUNIT_ASSERT( it->second.m_val == 0 ); - CPPUNIT_ASSERT( m.find(100) == m.end() ); + CPPUNIT_ASSERT( m.contains(100) == m.end() ); it = m.insert( 100, 200 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 2 )); - CPPUNIT_ASSERT( m.find_with(100, less()) == it ); + CPPUNIT_ASSERT( m.contains(100, less()) == it ); CPPUNIT_ASSERT( it->first == 100 ); CPPUNIT_ASSERT( it->second.m_val == 200 ); - CPPUNIT_ASSERT( m.find(55) == m.end() ); + CPPUNIT_ASSERT( m.contains(55) == m.end() ); it = m.insert_with( 55, insert_functor() ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( m.find(55) == it ); + CPPUNIT_ASSERT( m.contains(55) == it ); CPPUNIT_ASSERT( it->first == 55 ); CPPUNIT_ASSERT( it->second.m_val == 55 * 3 ); @@ -620,30 +625,33 @@ namespace map { CPPUNIT_ASSERT( m.insert( 55, 10 ) == m.end() ); CPPUNIT_ASSERT( m.insert_with( 55, insert_functor()) == m.end() ); - CPPUNIT_ASSERT( m.find(10) != m.end() ); - std::pair ensureResult = m.ensure( 10 ); - CPPUNIT_ASSERT( ensureResult.first != m.end() ); - CPPUNIT_ASSERT( !ensureResult.second ); + CPPUNIT_ASSERT( m.contains(10) != m.end() ); + std::pair updateResult = m.update(10, false); + CPPUNIT_ASSERT( updateResult.first != m.end() ); + CPPUNIT_ASSERT( !updateResult.second ); CPPUNIT_ASSERT( !m.empty() ); - ensureResult.first->second.m_val = ensureResult.first->first * 5; + updateResult.first->second.m_val = updateResult.first->first * 5; CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( m.find(10) == ensureResult.first ); - it = m.find(10); + CPPUNIT_ASSERT( m.contains(10) == updateResult.first ); + it = m.contains(10); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->second.m_val == 50 ); - CPPUNIT_ASSERT( m.find(120) == m.end() ); - ensureResult = m.ensure( 120 ); - CPPUNIT_ASSERT( ensureResult.first != m.end() ); - CPPUNIT_ASSERT( ensureResult.second ); + CPPUNIT_ASSERT( m.contains(120) == m.end() ); + updateResult = m.update(120, false); + CPPUNIT_ASSERT(updateResult.first == m.end()); + CPPUNIT_ASSERT(!updateResult.second); + updateResult = m.update( 120 ); + CPPUNIT_ASSERT( updateResult.first != m.end() ); + CPPUNIT_ASSERT( updateResult.second ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 4 )); - ensureResult.first->second.m_val = ensureResult.first->first * 5; - CPPUNIT_ASSERT( m.find_with(120, less()) == ensureResult.first ); - it = m.find_with(120, less()); + updateResult.first->second.m_val = updateResult.first->first * 5; + CPPUNIT_ASSERT( m.contains(120, less()) == updateResult.first ); + it = m.contains(120, less()); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->second.m_val == 120 * 5 ); - CPPUNIT_ASSERT( m.find_with(120, less()) == m.find(120) ); + CPPUNIT_ASSERT( m.contains(120, less()) == m.contains(120) ); // emplace test it = m.emplace( 151 ) ; // key = 151, val = 0 @@ -664,17 +672,17 @@ namespace map { it = m.emplace( 151, 1051 ); CPPUNIT_ASSERT( it == m.end()); - it = m.find( 174 ); + it = m.contains( 174 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->first == 174 ); CPPUNIT_ASSERT( it->second.m_val == 471 ); - it = m.find( 190 ); + it = m.contains( 190 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->first == 190 ); CPPUNIT_ASSERT( it->second.m_val == 91 ); - it = m.find( 151 ); + it = m.contains( 151 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->first == 151 ); CPPUNIT_ASSERT( it->second.m_val == 0 ); @@ -741,30 +749,30 @@ namespace map { CPPUNIT_ASSERT( m.empty() ); CPPUNIT_ASSERT( check_size( m, 0 )); - CPPUNIT_ASSERT( m.find(10) == m.end() ); + CPPUNIT_ASSERT( m.contains(10) == m.end() ); iterator it = m.insert( 10 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 1 )); - CPPUNIT_ASSERT( m.find(10) == it ); + CPPUNIT_ASSERT( m.contains(10) == it ); CPPUNIT_ASSERT( it->first == 10 ); CPPUNIT_ASSERT( it->second.m_val == 0 ); - CPPUNIT_ASSERT( m.find(100) == m.end() ); + CPPUNIT_ASSERT( m.contains(100) == m.end() ); it = m.insert( 100, 200 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 2 )); - CPPUNIT_ASSERT( m.find_with(100, equal()) == it ); + CPPUNIT_ASSERT( m.contains(100, equal()) == it ); CPPUNIT_ASSERT( it->first == 100 ); CPPUNIT_ASSERT( it->second.m_val == 200 ); - CPPUNIT_ASSERT( m.find(55) == m.end() ); + CPPUNIT_ASSERT( m.contains(55) == m.end() ); it = m.insert_with( 55, insert_functor() ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( m.find(55) == it ); + CPPUNIT_ASSERT( m.contains(55) == it ); CPPUNIT_ASSERT( it->first == 55 ); CPPUNIT_ASSERT( it->second.m_val == 55 * 3 ); @@ -772,30 +780,33 @@ namespace map { CPPUNIT_ASSERT( m.insert( 55, 10 ) == m.end() ); CPPUNIT_ASSERT( m.insert_with( 55, insert_functor()) == m.end() ); - CPPUNIT_ASSERT( m.find(10) != m.end() ); - std::pair ensureResult = m.ensure( 10 ); - CPPUNIT_ASSERT( ensureResult.first != m.end() ); - CPPUNIT_ASSERT( !ensureResult.second ); + CPPUNIT_ASSERT( m.contains(10) != m.end() ); + std::pair updateResult = m.update( 10 ); + CPPUNIT_ASSERT( updateResult.first != m.end() ); + CPPUNIT_ASSERT( !updateResult.second ); CPPUNIT_ASSERT( !m.empty() ); - ensureResult.first->second.m_val = ensureResult.first->first * 5; + updateResult.first->second.m_val = updateResult.first->first * 5; CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( m.find(10) == ensureResult.first ); - it = m.find(10); + CPPUNIT_ASSERT( m.contains(10) == updateResult.first ); + it = m.contains(10); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->second.m_val == 50 ); - CPPUNIT_ASSERT( m.find(120) == m.end() ); - ensureResult = m.ensure( 120 ); - CPPUNIT_ASSERT( ensureResult.first != m.end() ); - CPPUNIT_ASSERT( ensureResult.second ); + CPPUNIT_ASSERT( m.contains(120) == m.end() ); + updateResult = m.update(120, false); + CPPUNIT_ASSERT(updateResult.first == m.end()); + CPPUNIT_ASSERT(!updateResult.second); + updateResult = m.update( 120, true ); + CPPUNIT_ASSERT( updateResult.first != m.end() ); + CPPUNIT_ASSERT( updateResult.second ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 4 )); - ensureResult.first->second.m_val = ensureResult.first->first * 5; - CPPUNIT_ASSERT( m.find_with(120, equal()) == ensureResult.first ); - it = m.find_with(120, equal()); + updateResult.first->second.m_val = updateResult.first->first * 5; + CPPUNIT_ASSERT( m.contains(120, equal()) == updateResult.first ); + it = m.contains(120, equal()); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->second.m_val == 120 * 5 ); - CPPUNIT_ASSERT( m.find_with(120, equal()) == m.find(120) ); + CPPUNIT_ASSERT( m.contains(120, equal()) == m.contains(120) ); // emplace test it = m.emplace( 151 ) ; // key = 151, val = 0 @@ -816,17 +827,17 @@ namespace map { it = m.emplace( 151, 1051 ); CPPUNIT_ASSERT( it == m.end()); - it = m.find( 174 ); + it = m.contains( 174 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->first == 174 ); CPPUNIT_ASSERT( it->second.m_val == 471 ); - it = m.find( 190 ); + it = m.contains( 190 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->first == 190 ); CPPUNIT_ASSERT( it->second.m_val == 91 ); - it = m.find( 151 ); + it = m.contains( 151 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->first == 151 ); CPPUNIT_ASSERT( it->second.m_val == 0 ); diff --git a/tests/test-hdr/map/hdr_skiplist_map.h b/tests/test-hdr/map/hdr_skiplist_map.h index 5b57a815..22098989 100644 --- a/tests/test-hdr/map/hdr_skiplist_map.h +++ b/tests/test-hdr/map/hdr_skiplist_map.h @@ -39,7 +39,7 @@ namespace map { nPrevKey = 0; for ( set_iterator it = m.begin(), itEnd = m.end(); it != itEnd; ++it ) { CPPUNIT_ASSERT( (*it).first == it->second.m_val ); - CPPUNIT_ASSERT( m.find( it->first )); + CPPUNIT_ASSERT( m.contains( it->first )); it->second.m_val = (*it).first * 2; ++nCount; if ( it != m.begin() ) { @@ -73,7 +73,7 @@ namespace map { nPrevKey = 0; for ( set_iterator it = m.begin(), itEnd = m.end(); it != itEnd; ++it ) { CPPUNIT_ASSERT( (*it).first * 2 == it->second.m_val ); - CPPUNIT_ASSERT( m.find( it->first )); + CPPUNIT_ASSERT( m.contains( it->first )); it->second.m_val = (*it).first; ++nCount; if ( it != m.begin() ) { @@ -114,7 +114,7 @@ namespace map { nPrevKey = 0; for ( set_iterator it = m.begin(), itEnd = m.end(); it != itEnd; ++it ) { CPPUNIT_ASSERT( (*it).first == it->second.m_val ); - CPPUNIT_ASSERT( m.find( it->first )); + CPPUNIT_ASSERT( m.contains( it->first )); it->second.m_val = (*it).first * 2; ++nCount; if ( it != m.begin() ) { @@ -242,32 +242,32 @@ namespace map { CPPUNIT_ASSERT( m.empty() ); CPPUNIT_ASSERT( check_size( m, 0 )); - CPPUNIT_ASSERT( m.find(10) == m.end() ); + CPPUNIT_ASSERT( m.contains(10) == m.end() ); iterator it = m.insert( 10 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->first == 10 ); CPPUNIT_ASSERT( it->second.m_val == 0 ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 1 )); - CPPUNIT_ASSERT( m.find(10) == it ); + CPPUNIT_ASSERT( m.contains(10) == it ); CPPUNIT_ASSERT( it->first == 10 ); CPPUNIT_ASSERT( it->second.m_val == 0 ); - CPPUNIT_ASSERT( m.find(100) == m.end() ); + CPPUNIT_ASSERT( m.contains(100) == m.end() ); it = m.insert( 100, 200 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 2 )); - CPPUNIT_ASSERT( m.find(100) == it ); + CPPUNIT_ASSERT( m.contains(100) == it ); CPPUNIT_ASSERT( it->first == 100 ); CPPUNIT_ASSERT( it->second.m_val == 200 ); - CPPUNIT_ASSERT( m.find(55) == m.end() ); + CPPUNIT_ASSERT( m.contains(55) == m.end() ); it = m.insert_with( 55, insert_functor() ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( m.find(55) == it ); + CPPUNIT_ASSERT( m.contains(55) == it ); CPPUNIT_ASSERT( it->first == 55 ); CPPUNIT_ASSERT( it->second.m_val == 55 * 3 ); @@ -275,27 +275,30 @@ namespace map { CPPUNIT_ASSERT( m.insert( 55, 10 ) == m.end() ); CPPUNIT_ASSERT( m.insert_with( 55, insert_functor()) == m.end() ); - CPPUNIT_ASSERT( m.find(10) != m.end() ); - std::pair ensureResult = m.ensure( 10 ); - CPPUNIT_ASSERT( ensureResult.first != m.end() ); - CPPUNIT_ASSERT( !ensureResult.second ); + CPPUNIT_ASSERT( m.contains(10) != m.end() ); + std::pair updateResult = m.update( 10, false ); + CPPUNIT_ASSERT( updateResult.first != m.end() ); + CPPUNIT_ASSERT( !updateResult.second ); CPPUNIT_ASSERT( !m.empty() ); - ensureResult.first->second.m_val = ensureResult.first->first * 5; + updateResult.first->second.m_val = updateResult.first->first * 5; CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( m.find(10) == ensureResult.first ); - it = m.find_with( 10, typename base_class::less() ); + CPPUNIT_ASSERT( m.contains(10) == updateResult.first ); + it = m.contains( 10, typename base_class::less() ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->second.m_val == 50 ); - CPPUNIT_ASSERT( m.find_with(120, base_class::less()) == m.end() ); - ensureResult = m.ensure( 120 ); - CPPUNIT_ASSERT( ensureResult.first != m.end() ); - CPPUNIT_ASSERT( ensureResult.second ); + CPPUNIT_ASSERT( m.contains(120, base_class::less()) == m.end() ); + updateResult = m.update(120, false); + CPPUNIT_ASSERT(updateResult.first == m.end()); + CPPUNIT_ASSERT(!updateResult.second); + updateResult = m.update( 120 ); + CPPUNIT_ASSERT( updateResult.first != m.end() ); + CPPUNIT_ASSERT( updateResult.second ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 4 )); - ensureResult.first->second.m_val = ensureResult.first->first * 5; - CPPUNIT_ASSERT( m.find_with(120, base_class::less()) == ensureResult.first ); - it = m.find_with(120, base_class::less()); + updateResult.first->second.m_val = updateResult.first->first * 5; + CPPUNIT_ASSERT( m.contains(120, base_class::less()) == updateResult.first ); + it = m.contains(120, base_class::less()); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->second.m_val == 120 * 5 ); @@ -318,17 +321,17 @@ namespace map { it = m.emplace( 151, 1051 ); CPPUNIT_ASSERT( it == m.end()); - it = m.find( 174 ); + it = m.contains( 174 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->first == 174 ); CPPUNIT_ASSERT( it->second.m_val == 471 ); - it = m.find( 190 ); + it = m.contains( 190 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->first == 190 ); CPPUNIT_ASSERT( it->second.m_val == 91 ); - it = m.find( 151 ); + it = m.contains( 151 ); CPPUNIT_ASSERT( it != m.end() ); CPPUNIT_ASSERT( it->first == 151 ); CPPUNIT_ASSERT( it->second.m_val == 0 ); diff --git a/tests/test-hdr/map/hdr_skiplist_map_rcu.h b/tests/test-hdr/map/hdr_skiplist_map_rcu.h index b5b28e76..aecfd2fc 100644 --- a/tests/test-hdr/map/hdr_skiplist_map_rcu.h +++ b/tests/test-hdr/map/hdr_skiplist_map_rcu.h @@ -42,7 +42,7 @@ namespace map { rcu_lock sl; for ( set_iterator it = m.begin(), itEnd = m.end(); it != itEnd; ++it ) { CPPUNIT_ASSERT( (*it).first == it->second.m_val ); - CPPUNIT_ASSERT( m.find( it->first )); + CPPUNIT_ASSERT( m.contains( it->first )); it->second.m_val = (*it).first * 2; ++nCount; if ( it != m.begin() ) { @@ -82,7 +82,7 @@ namespace map { rcu_lock sl; for ( set_iterator it = m.begin(), itEnd = m.end(); it != itEnd; ++it ) { CPPUNIT_ASSERT( (*it).first * 2 == it->second.m_val ); - CPPUNIT_ASSERT( m.find( it->first )); + CPPUNIT_ASSERT( m.contains( it->first )); it->second.m_val = (*it).first; ++nCount; if ( it != m.begin() ) { @@ -129,7 +129,7 @@ namespace map { rcu_lock sl; for ( set_iterator it = m.begin(), itEnd = m.end(); it != itEnd; ++it ) { CPPUNIT_ASSERT( (*it).first == it->second.m_val ); - CPPUNIT_ASSERT( m.find( it->first )); + CPPUNIT_ASSERT( m.contains( it->first )); it->second.m_val = (*it).first * 2; ++nCount; if ( it != m.begin() ) { diff --git a/tests/test-hdr/map/hdr_striped_map.h b/tests/test-hdr/map/hdr_striped_map.h index 9d5b35b9..071a78fb 100644 --- a/tests/test-hdr/map/hdr_striped_map.h +++ b/tests/test-hdr/map/hdr_striped_map.h @@ -120,7 +120,7 @@ namespace map { item.second.m_val = item.first * 3; } - // ensure ftor + // update() ftor void operator()( bool bNew, pair_type& item ) { if ( bNew ) @@ -161,49 +161,54 @@ namespace map { template void test_int_with( Map& m ) { - std::pair ensureResult; + std::pair updateResult; // insert CPPUNIT_ASSERT( m.empty() ); CPPUNIT_ASSERT( check_size( m, 0 )); - CPPUNIT_ASSERT( !m.find(25) ); + CPPUNIT_ASSERT( !m.contains(25) ); CPPUNIT_ASSERT( m.insert( 25 ) ) ; // value = 0 - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 1 )); - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( !m.insert( 25 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 1 )); - CPPUNIT_ASSERT( !m.find(10) ); + CPPUNIT_ASSERT( !m.contains(10) ); CPPUNIT_ASSERT( m.insert( 10, 10 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 2 )); - CPPUNIT_ASSERT( m.find(10) ); + CPPUNIT_ASSERT( m.contains(10) ); CPPUNIT_ASSERT( !m.insert( 10, 20 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 2 )); - CPPUNIT_ASSERT( !m.find(30) ); + CPPUNIT_ASSERT( !m.contains(30) ); CPPUNIT_ASSERT( m.insert_with( 30, insert_functor() ) ) ; // value = 90 CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( m.find(30) ); + CPPUNIT_ASSERT( m.contains(30) ); CPPUNIT_ASSERT( !m.insert_with( 10, insert_functor() ) ); CPPUNIT_ASSERT( !m.insert_with( 25, insert_functor() ) ); CPPUNIT_ASSERT( !m.insert_with( 30, insert_functor() ) ); - // ensure (new key) - CPPUNIT_ASSERT( !m.find(27) ); - ensureResult = m.ensure( 27, insert_functor() ) ; // value = 54 - CPPUNIT_ASSERT( ensureResult.first ); - CPPUNIT_ASSERT( ensureResult.second ); + // update() (new key) + CPPUNIT_ASSERT( !m.contains(27) ); + updateResult = m.update(27, insert_functor(), false); + CPPUNIT_ASSERT(!updateResult.first); + CPPUNIT_ASSERT(!updateResult.second); + CPPUNIT_ASSERT(check_size(m, 3)); + CPPUNIT_ASSERT(!m.contains(27)); + updateResult = m.update( 27, insert_functor() ) ; // value = 54 + CPPUNIT_ASSERT( updateResult.first ); + CPPUNIT_ASSERT( updateResult.second ); CPPUNIT_ASSERT( check_size( m, 4 )); - CPPUNIT_ASSERT( m.find(27) ); + CPPUNIT_ASSERT( m.contains(27) ); // find test check_value chk(10); @@ -215,39 +220,39 @@ namespace map { chk.m_nExpected = 54; CPPUNIT_ASSERT( m.find( 27, std::ref( chk ) ) ); - ensureResult = m.ensure( 10, insert_functor() ) ; // value = 50 - CPPUNIT_ASSERT( ensureResult.first ); - CPPUNIT_ASSERT( !ensureResult.second ); + updateResult = m.update( 10, insert_functor() ) ; // value = 50 + CPPUNIT_ASSERT( updateResult.first ); + CPPUNIT_ASSERT( !updateResult.second ); chk.m_nExpected = 50; CPPUNIT_ASSERT( m.find( 10, std::ref( chk ) ) ); // erase test - CPPUNIT_ASSERT( !m.find(100) ); + CPPUNIT_ASSERT( !m.contains(100) ); CPPUNIT_ASSERT( !m.erase( 100 )) ; // not found - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( check_size( m, 4 )); CPPUNIT_ASSERT( m.erase( 25 )); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( !m.find(25) ); + CPPUNIT_ASSERT( !m.contains(25) ); CPPUNIT_ASSERT( !m.erase( 25 )); - CPPUNIT_ASSERT( !m.find(258) ); + CPPUNIT_ASSERT( !m.contains(258) ); CPPUNIT_ASSERT( m.insert(258)) CPPUNIT_ASSERT( check_size( m, 4 )); - CPPUNIT_ASSERT( m.find(258) ); + CPPUNIT_ASSERT( m.contains(258) ); CPPUNIT_ASSERT( m.erase( 258 )); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( !m.find(258) ); + CPPUNIT_ASSERT( !m.contains(258) ); CPPUNIT_ASSERT( !m.erase( 258 )); int nVal; extract_functor ext; ext.m_pVal = &nVal; - CPPUNIT_ASSERT( !m.find(29) ); + CPPUNIT_ASSERT( !m.contains(29) ); CPPUNIT_ASSERT( m.insert(29, 290)); CPPUNIT_ASSERT( check_size( m, 4 )); CPPUNIT_ASSERT( m.erase( 29, std::ref( ext ) ) ); @@ -366,48 +371,52 @@ namespace map { template void test_int_with2( Map& m ) { - std::pair ensureResult; + std::pair updateResult; // insert CPPUNIT_ASSERT( m.empty() ); CPPUNIT_ASSERT( check_size( m, 0 )); - CPPUNIT_ASSERT( !m.find(25) ); + CPPUNIT_ASSERT( !m.contains(25) ); CPPUNIT_ASSERT( m.insert( 25 ) ) ; // value = 0 - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 1 )); - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( !m.insert( 25 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 1 )); - CPPUNIT_ASSERT( !m.find_with(10, less()) ); + CPPUNIT_ASSERT( !m.contains(10, less()) ); CPPUNIT_ASSERT( m.insert( 10, 10 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 2 )); - CPPUNIT_ASSERT( m.find_with(10, less()) ); + CPPUNIT_ASSERT( m.contains(10, less()) ); CPPUNIT_ASSERT( !m.insert( 10, 20 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 2 )); - CPPUNIT_ASSERT( !m.find(30) ); + CPPUNIT_ASSERT( !m.contains(30) ); CPPUNIT_ASSERT( m.insert_with( 30, insert_functor() ) ) ; // value = 90 CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( m.find(30) ); + CPPUNIT_ASSERT( m.contains(30) ); CPPUNIT_ASSERT( !m.insert_with( 10, insert_functor() ) ); CPPUNIT_ASSERT( !m.insert_with( 25, insert_functor() ) ); CPPUNIT_ASSERT( !m.insert_with( 30, insert_functor() ) ); - // ensure (new key) - CPPUNIT_ASSERT( !m.find(27) ); - ensureResult = m.ensure( 27, insert_functor() ) ; // value = 54 - CPPUNIT_ASSERT( ensureResult.first ); - CPPUNIT_ASSERT( ensureResult.second ); - CPPUNIT_ASSERT( m.find(27) ); + // update() (new key) + CPPUNIT_ASSERT( !m.contains(27) ); + updateResult = m.update(27, insert_functor(), false); + CPPUNIT_ASSERT(!updateResult.first); + CPPUNIT_ASSERT(!updateResult.second); + CPPUNIT_ASSERT(!m.contains(27)); + updateResult = m.update( 27, insert_functor() ) ; // value = 54 + CPPUNIT_ASSERT( updateResult.first ); + CPPUNIT_ASSERT( updateResult.second ); + CPPUNIT_ASSERT( m.contains(27) ); // find test check_value chk(10); @@ -419,39 +428,39 @@ namespace map { chk.m_nExpected = 54; CPPUNIT_ASSERT( m.find( 27, std::ref( chk ) ) ); - ensureResult = m.ensure( 10, insert_functor() ) ; // value = 50 - CPPUNIT_ASSERT( ensureResult.first ); - CPPUNIT_ASSERT( !ensureResult.second ); + updateResult = m.update( 10, insert_functor(), false ) ; // value = 50 + CPPUNIT_ASSERT( updateResult.first ); + CPPUNIT_ASSERT( !updateResult.second ); chk.m_nExpected = 50; CPPUNIT_ASSERT( m.find( 10, std::ref( chk ) ) ); // erase test - CPPUNIT_ASSERT( !m.find(100) ); + CPPUNIT_ASSERT( !m.contains(100) ); CPPUNIT_ASSERT( !m.erase( 100 )) ; // not found - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( check_size( m, 4 )); CPPUNIT_ASSERT( m.erase( 25 )); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( !m.find(25) ); + CPPUNIT_ASSERT( !m.contains(25) ); CPPUNIT_ASSERT( !m.erase( 25 )); - CPPUNIT_ASSERT( !m.find(258) ); + CPPUNIT_ASSERT( !m.contains(258) ); CPPUNIT_ASSERT( m.insert(258)) CPPUNIT_ASSERT( check_size( m, 4 )); - CPPUNIT_ASSERT( m.find_with(258, less()) ); + CPPUNIT_ASSERT( m.contains(258, less()) ); CPPUNIT_ASSERT( m.erase_with( 258, less() )); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( !m.find(258) ); + CPPUNIT_ASSERT( !m.contains(258) ); CPPUNIT_ASSERT( !m.erase_with( 258, less() )); int nVal; extract_functor ext; ext.m_pVal = &nVal; - CPPUNIT_ASSERT( !m.find(29) ); + CPPUNIT_ASSERT( !m.contains(29) ); CPPUNIT_ASSERT( m.insert(29, 290)) CPPUNIT_ASSERT( m.erase_with( 29, less(), std::ref( ext ) ) ); CPPUNIT_ASSERT( !m.empty() ); -- 2.34.1