X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=blobdiff_plain;f=test%2Funit%2Fset%2Ftest_set.h;h=af88b5b58b4ea75287ca4b13d2e1537db630eacf;hp=1f6e142a84d1d973e38629af0a750f219234384c;hb=025501fba2f37ec3e8dd0f187c49fc22c18ed951;hpb=bdc2702066c3ea28d5ee5d6a7926bed04d34af11 diff --git a/test/unit/set/test_set.h b/test/unit/set/test_set.h index 1f6e142a..af88b5b5 100644 --- a/test/unit/set/test_set.h +++ b/test/unit/set/test_set.h @@ -5,7 +5,7 @@ Source code repo: http://github.com/khizmax/libcds/ Download: http://sourceforge.net/projects/libcds/files/ - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -25,205 +25,20 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef CDSUNIT_SET_TEST_SET_H #define CDSUNIT_SET_TEST_SET_H -#include -#include +#include "test_set_data.h" #include -#include // ref - -// forward declaration -namespace cds { namespace container {}} namespace cds_test { - namespace co = cds::opt; - class container_set : public fixture + class container_set : public container_set_data { - public: - static size_t const kSize = 100; - - struct stat - { - unsigned int nFindCount; - unsigned int nUpdateNewCount; - unsigned int nUpdateCount; - mutable unsigned int nEraseCount; - - stat() - { - clear_stat(); - } - - void clear_stat() - { - memset( this, 0, sizeof( *this ) ); - } - }; - - struct other_item { - int nKey; - - explicit other_item( int k ) - : nKey( k ) - {} - - int key() const - { - return nKey; - } - }; - - struct int_item: public stat - { - int nKey; - int nVal; - std::string strVal; - - int_item() - : nKey( 0 ) - , nVal( 0 ) - {} - - explicit int_item( int k ) - : nKey( k ) - , nVal( k * 2 ) - {} - - template - explicit int_item( Q const& src ) - : nKey( src.key() ) - , nVal( 0 ) - {} - - int_item( int_item const& src ) - : nKey( src.nKey ) - , nVal( src.nVal ) - , strVal( src.strVal ) - {} - - int_item( int_item&& src ) - : nKey( src.nKey ) - , nVal( src.nVal ) - , strVal( std::move( src.strVal ) ) - {} - - int_item( int k, std::string&& s ) - : nKey( k ) - , nVal( k * 2 ) - , strVal( std::move( s ) ) - {} - - explicit int_item( other_item const& s ) - : nKey( s.key() ) - , nVal( s.key() * 2 ) - {} - - int key() const - { - return nKey; - } - }; - - struct hash_int { - size_t operator()( int i ) const - { - return co::v::hash()(i); - } - template - size_t operator()( const Item& i ) const - { - return (*this)(i.key()); - } - }; - - struct simple_item_counter { - size_t m_nCount; - - simple_item_counter() - : m_nCount( 0 ) - {} - - size_t operator ++() - { - return ++m_nCount; - } - - size_t operator --() - { - return --m_nCount; - } - - void reset() - { - m_nCount = 0; - } - - operator size_t() const - { - return m_nCount; - } - - }; - - struct less - { - bool operator ()( int_item const& v1, int_item const& v2 ) const - { - return v1.key() < v2.key(); - } - - template - bool operator ()( int_item const& v1, const Q& v2 ) const - { - return v1.key() < v2; - } - - template - bool operator ()( const Q& v1, int_item const& v2 ) const - { - return v1 < v2.key(); - } - }; - - struct cmp { - int operator ()( int_item const& v1, int_item const& v2 ) const - { - if ( v1.key() < v2.key() ) - return -1; - return v1.key() > v2.key() ? 1 : 0; - } - - template - int operator ()( T const& v1, int v2 ) const - { - if ( v1.key() < v2 ) - return -1; - return v1.key() > v2 ? 1 : 0; - } - - template - int operator ()( int v1, T const& v2 ) const - { - if ( v1 < v2.key() ) - return -1; - return v1 > v2.key() ? 1 : 0; - } - }; - - struct other_less { - template - bool operator()( Q const& lhs, T const& rhs ) const - { - return lhs.key() < rhs.key(); - } - }; - protected: template void test( Set& s ) @@ -261,7 +76,7 @@ namespace cds_test { std::pair updResult; std::string str; - updResult = s.update( i.key(), []( bool bNew, value_type&, int ) + updResult = s.update( i.key(), []( bool, value_type&, int ) { ASSERT_TRUE( false ); }, false ); @@ -297,7 +112,7 @@ namespace cds_test { ASSERT_TRUE( s.find( i.nKey, []( value_type const& v, int key ) { EXPECT_EQ( v.key(), key ); - EXPECT_EQ( v.nFindCount, 1 ); + EXPECT_EQ( v.nFindCount, 1u ); })); break; case 3: @@ -306,7 +121,7 @@ namespace cds_test { ASSERT_TRUE( s.find( i.nKey, []( value_type const& v, int key ) { EXPECT_EQ( v.key(), key ); - EXPECT_EQ( v.nFindCount, 1 ); + EXPECT_EQ( v.nFindCount, 1u ); })); break; case 4: @@ -331,7 +146,7 @@ namespace cds_test { ASSERT_TRUE( s.find( i.nKey, []( value_type const& v, int key ) { EXPECT_EQ( v.key(), key ); - EXPECT_EQ( v.nUpdateNewCount, 2 ); + EXPECT_EQ( v.nUpdateNewCount, 2u ); })); break; case 5: @@ -356,7 +171,7 @@ namespace cds_test { ASSERT_TRUE( s.find( i, []( value_type const& v, value_type const& arg ) { EXPECT_EQ( v.key(), arg.key() ); - EXPECT_EQ( v.nUpdateNewCount, 2 ); + EXPECT_EQ( v.nUpdateNewCount, 2u ); })); break; case 6: @@ -408,11 +223,11 @@ namespace cds_test { })); ASSERT_TRUE( s.find( i, []( value_type& v, value_type const& ) { - EXPECT_EQ( ++v.nFindCount, 2 ); + EXPECT_EQ( ++v.nFindCount, 2u ); })); ASSERT_TRUE( s.find_with( other_item( i.key() ), other_less(), []( value_type& v, other_item const& ) { - EXPECT_EQ( ++v.nFindCount, 3 ); + EXPECT_EQ( ++v.nFindCount, 3u ); })); int nKey = i.key() - 1; @@ -481,7 +296,7 @@ namespace cds_test { ASSERT_FALSE( s.find_with( other_item( i.key()), other_less(), []( value_type&, other_item const& ) {} )); } ASSERT_TRUE( s.empty() ); - ASSERT_CONTAINER_SIZE( s, 0 ); + ASSERT_CONTAINER_SIZE( s, 0u ); // clear @@ -495,7 +310,7 @@ namespace cds_test { s.clear(); ASSERT_TRUE( s.empty() ); - ASSERT_CONTAINER_SIZE( s, 0 ); + ASSERT_CONTAINER_SIZE( s, 0u ); ASSERT_TRUE( s.begin() == s.end() ); ASSERT_TRUE( s.cbegin() == s.cend() );