From 15d0c51841dde59f8e07ccea865ac1bbad1e271a Mon Sep 17 00:00:00 2001 From: Mike Krinkin Date: Sat, 28 Mar 2015 16:14:51 +0300 Subject: [PATCH] Add michael set test with unordered lazy list. --- .../set/hdr_michael_set_lazy_nogc.cpp | 24 +++ tests/test-hdr/set/hdr_set.h | 141 ++++++++++++++++++ 2 files changed, 165 insertions(+) diff --git a/tests/test-hdr/set/hdr_michael_set_lazy_nogc.cpp b/tests/test-hdr/set/hdr_michael_set_lazy_nogc.cpp index 4d988f43..ac4de700 100644 --- a/tests/test-hdr/set/hdr_michael_set_lazy_nogc.cpp +++ b/tests/test-hdr/set/hdr_michael_set_lazy_nogc.cpp @@ -23,6 +23,12 @@ namespace set { typedef HashSetHdrTest::less less; }; + struct nogc_equal_traits: public cc::lazy_list::traits + { + typedef HashSetHdrTest::equal equal_to; + static const bool sort = false; + }; + struct nogc_cmpmix_traits: public cc::lazy_list::traits { typedef HashSetHdrTest::cmp compare; @@ -66,6 +72,24 @@ namespace set { test_int_nogc< opt_set >(); } + void HashSetHdrTest::Lazy_nogc_equal() + { + typedef cc::LazyList< cds::gc::nogc, item, nogc_equal_traits > list; + + // traits-based version + typedef cc::MichaelHashSet< cds::gc::nogc, list, set_traits > set; + test_int_nogc_unordered< set >(); + + // option-based version + typedef cc::MichaelHashSet< cds::gc::nogc, list, + cc::michael_set::make_traits< + cc::opt::hash< hash_int > + ,cc::opt::item_counter< simple_item_counter > + >::type + > opt_set; + test_int_nogc_unordered< opt_set >(); + } + void HashSetHdrTest::Lazy_nogc_cmpmix() { typedef cc::LazyList< cds::gc::nogc, item, nogc_cmpmix_traits > list; diff --git a/tests/test-hdr/set/hdr_set.h b/tests/test-hdr/set/hdr_set.h index 61dc034c..643b7c25 100644 --- a/tests/test-hdr/set/hdr_set.h +++ b/tests/test-hdr/set/hdr_set.h @@ -803,6 +803,145 @@ namespace set { } } + template + void test_int_nogc_unordered() + { + typedef typename Set::value_type value_type; + typedef typename Set::iterator iterator; + typedef typename Set::const_iterator const_iterator; + + { + Set s( 52, 4 ); + iterator it; + + CPPUNIT_ASSERT( s.empty() ); + CPPUNIT_ASSERT( check_size( s, 0 )); + + // insert + it = s.insert( 10 ); + CPPUNIT_ASSERT( it != s.end() ); + CPPUNIT_ASSERT( it->key() == 10 ); + CPPUNIT_ASSERT( it->val() == 10 ); + CPPUNIT_ASSERT( !s.empty() ); + CPPUNIT_ASSERT( check_size( s, 1 )); + CPPUNIT_ASSERT( s.insert( 10 ) == s.end() ); + + it = s.insert( std::make_pair( 50, 25 )); + CPPUNIT_ASSERT( it != s.end() ); + CPPUNIT_ASSERT( it->key() == 50 ); + CPPUNIT_ASSERT( it->val() == 25 ); + CPPUNIT_ASSERT( !s.empty() ); + CPPUNIT_ASSERT( check_size( s, 2 )); + CPPUNIT_ASSERT( s.insert( 50 ) == s.end() ); + + // ensure + std::pair< iterator, bool> ensureResult; + ensureResult = s.ensure( 20 ); + CPPUNIT_ASSERT( ensureResult.first != s.end() ); + CPPUNIT_ASSERT( ensureResult.second ); + CPPUNIT_ASSERT( ensureResult.first->key() == 20 ); + CPPUNIT_ASSERT( ensureResult.first->val() == 20 ); + CPPUNIT_ASSERT( !s.empty() ); + CPPUNIT_ASSERT( check_size( s, 3 )); + + ensureResult = s.ensure( std::make_pair( 20, 200 )); + CPPUNIT_ASSERT( ensureResult.first != s.end() ); + CPPUNIT_ASSERT( !ensureResult.second ); + CPPUNIT_ASSERT( ensureResult.first->key() == 20 ); + CPPUNIT_ASSERT( ensureResult.first->val() == 20 ); + CPPUNIT_ASSERT( !s.empty() ); + CPPUNIT_ASSERT( check_size( s, 3 )); + ensureResult.first->nVal = 22; + + ensureResult = s.ensure( std::make_pair( 30, 33 )); + CPPUNIT_ASSERT( ensureResult.first != s.end() ); + CPPUNIT_ASSERT( ensureResult.second ); + CPPUNIT_ASSERT( ensureResult.first->key() == 30 ); + CPPUNIT_ASSERT( ensureResult.first->val() == 33 ); + CPPUNIT_ASSERT( !s.empty() ); + CPPUNIT_ASSERT( check_size( s, 4 )); + + // find + it = s.find( 10 ); + CPPUNIT_ASSERT( it != s.end() ); + CPPUNIT_ASSERT( it->key() == 10 ); + CPPUNIT_ASSERT( it->val() == 10 ); + + it = s.find_with( 20, equal() ); + CPPUNIT_ASSERT( it != s.end() ); + CPPUNIT_ASSERT( it->key() == 20 ); + CPPUNIT_ASSERT( it->val() == 22 ); + + it = s.find( 30 ); + CPPUNIT_ASSERT( it != s.end() ); + CPPUNIT_ASSERT( it->key() == 30 ); + CPPUNIT_ASSERT( it->val() == 33 ); + + it = s.find( 40 ); + CPPUNIT_ASSERT( it == s.end() ); + + it = s.find( 50 ); + CPPUNIT_ASSERT( it != s.end() ); + CPPUNIT_ASSERT( it->key() == 50 ); + CPPUNIT_ASSERT( it->val() == 25 ); + + // emplace test + it = s.emplace( 151 ) ; // key = 151, val = 151 + CPPUNIT_ASSERT( it != s.end() ); + CPPUNIT_ASSERT( it->key() == 151 ); + CPPUNIT_ASSERT( it->val() == 151 ); + + it = s.emplace( 174, 471 ) ; // key == 174, val = 471 + CPPUNIT_ASSERT( it != s.end() ); + CPPUNIT_ASSERT( it->key() == 174 ); + CPPUNIT_ASSERT( it->val() == 471 ); + + it = s.emplace( std::make_pair( 190, 91 )) ; // key == 190, val = 91 + CPPUNIT_ASSERT( it != s.end() ); + CPPUNIT_ASSERT( it->key() == 190 ); + CPPUNIT_ASSERT( it->val() == 91 ); + + it = s.find( 174 ); + CPPUNIT_ASSERT( it != s.end() ); + CPPUNIT_ASSERT( it->key() == 174 ); + CPPUNIT_ASSERT( it->val() == 471 ); + + it = s.find_with( 190, equal() ); + CPPUNIT_ASSERT( it != s.end() ); + CPPUNIT_ASSERT( it->key() == 190 ); + CPPUNIT_ASSERT( it->val() == 91 ); + + it = s.find( 151 ); + CPPUNIT_ASSERT( it != s.end() ); + CPPUNIT_ASSERT( it->key() == 151 ); + CPPUNIT_ASSERT( it->val() == 151 ); + + //s.clear(); + //CPPUNIT_ASSERT( s.empty() ); + //CPPUNIT_ASSERT( check_size( s, 0 )); + } + + { + Set s( 52, 4 ); + + // iterator test + for ( int i = 0; i < 500; ++i ) { + CPPUNIT_ASSERT( s.insert( std::make_pair( i, i * 2) ) != s.end() ); + } + for ( iterator it = s.begin(), itEnd = s.end(); it != itEnd; ++it ) { + iterator it2 = it; + CPPUNIT_CHECK( it2 == it ); + CPPUNIT_CHECK( it2 != itEnd ); + CPPUNIT_ASSERT( (*it).nKey * 2 == it->nVal ); + it->nVal = (*it).nKey; + } + + Set const& refSet = s; + for ( const_iterator it = refSet.begin(), itEnd = refSet.end(); it != itEnd; ++it ) { + CPPUNIT_ASSERT( (*it).nKey == it->nVal ); + } + } + } template void test_iter() { @@ -922,6 +1061,7 @@ namespace set { void Lazy_nogc_cmp(); void Lazy_nogc_less(); + void Lazy_nogc_equal(); void Lazy_nogc_cmpmix(); void Split_HP_cmp(); @@ -1068,6 +1208,7 @@ namespace set { CPPUNIT_TEST(Lazy_nogc_cmp) CPPUNIT_TEST(Lazy_nogc_less) + CPPUNIT_TEST(Lazy_nogc_equal) CPPUNIT_TEST(Lazy_nogc_cmpmix) CPPUNIT_TEST(Split_HP_cmp) -- 2.34.1