void testInterleavedSortingWithPops() { DPQ dpq; IndexVector idVector; const Index MAXI( 101 ); for( int n( MAXI-1 ); n != 0 ; n-=2 ) { const Index id( dpq.push( n ) ); if( n == 12 || n == 46 ) { idVector.push_back( id ); } } dpq.pop( idVector.back() ); idVector.pop_back(); BOOST_CHECK_EQUAL( MAXI/2 -1, dpq.getSize() ); BOOST_CHECK( dpq.checkConsistency() ); for( int n( MAXI ); n != -1 ; n-=2 ) { const Index id( dpq.push( n ) ); if( n == 17 || n == 81 ) { idVector.push_back( id ); } } for( typename IndexVector::const_iterator i( idVector.begin() ); i != idVector.end(); ++i ) { dpq.pop( *i ); } BOOST_CHECK( dpq.checkConsistency() ); BOOST_CHECK_EQUAL( MAXI-4, dpq.getSize() ); int n( 0 ); while( ! dpq.isEmpty() ) { ++n; if( n == 12 || n == 46 || n == 17 || n == 81 ) { continue; } BOOST_CHECK_EQUAL( n, dpq.getTop() ); dpq.popTop(); } BOOST_CHECK_EQUAL( MAXI, Index( n ) ); BOOST_CHECK( dpq.isEmpty() ); BOOST_CHECK( dpq.checkConsistency() ); }
BOOST_AUTO_TEST_CASE_TEMPLATE( testPushAfterPop, DPQ, both ) { DPQ dpq; dpq.push( 1 ); const ID id1( dpq.push( 2 ) ); dpq.push( 3 ); dpq.push( 4 ); BOOST_CHECK( dpq.getSize() == 4 ); BOOST_CHECK( dpq.check() ); BOOST_CHECK( dpq.getTop() == 1 ); dpq.pop( id1 ); BOOST_CHECK( dpq.getSize() == 3 ); BOOST_CHECK( dpq.check() ); dpq.push( 1 ); BOOST_CHECK( dpq.getSize() == 4 ); BOOST_CHECK( dpq.check() ); BOOST_CHECK( dpq.getTop() == 1 ); dpq.popTop(); BOOST_CHECK( dpq.getTop() == 1 ); dpq.popTop(); BOOST_CHECK( dpq.getTop() == 3 ); dpq.popTop(); BOOST_CHECK( dpq.getTop() == 4 ); dpq.popTop(); BOOST_CHECK( dpq.isEmpty() ); BOOST_CHECK( dpq.check() ); }
BOOST_AUTO_TEST_CASE_TEMPLATE( testPushAfterPopTwoItems, DPQ, both ) { DPQ dpq; const ID id1( dpq.push( 2 ) ); dpq.push( 1 ); BOOST_CHECK( dpq.getSize() == 2 ); BOOST_CHECK( dpq.check() ); BOOST_CHECK( dpq.getTop() == 1 ); dpq.pop( id1 ); BOOST_CHECK( dpq.getSize() == 1 ); BOOST_CHECK( dpq.check() ); }
BOOST_AUTO_TEST_CASE_TEMPLATE( testSimpleSortingWithPops, DPQ, novolatile ) { DPQ dpq; typedef typename DPQ::Index Index; IDVector idVector; const Index MAXI( 100 ); for( int n( MAXI ); n != 0 ; --n ) { ID id( dpq.push( n ) ); if( n == 11 || n == 45 ) { idVector.push_back( id ); } } BOOST_CHECK( dpq.check() ); BOOST_CHECK_EQUAL( MAXI, dpq.getSize() ); for( IDVector::const_iterator i( idVector.begin() ); i != idVector.end(); ++i ) { dpq.pop( *i ); } BOOST_CHECK_EQUAL( MAXI - 2, dpq.getSize() ); int n( 0 ); while( ! dpq.isEmpty() ) { ++n; if( n == 11 || n == 45 ) { continue; // skip } BOOST_CHECK_EQUAL( int( n ), dpq.getTop() ); dpq.popTop(); } BOOST_CHECK_EQUAL( MAXI, Index( n ) ); BOOST_CHECK( dpq.isEmpty() ); BOOST_CHECK( dpq.check() ); }
void testSimpleSortingWithPops() { DPQ dpq; IndexVector idVector; const Index MAXI( 100 ); for( int n( MAXI ); n != 0 ; --n ) { Index id( dpq.push( n ) ); if( n == 11 || n == 45 ) { idVector.push_back( id ); } } BOOST_CHECK( dpq.checkConsistency() ); BOOST_CHECK_EQUAL( MAXI, dpq.getSize() ); for( typename IndexVector::const_iterator i( idVector.begin() ); i != idVector.end(); ++i ) { dpq.pop( *i ); } BOOST_CHECK_EQUAL( MAXI - 2, dpq.getSize() ); int n( 0 ); while( ! dpq.isEmpty() ) { ++n; if( n == 11 || n == 45 ) { continue; // skip } BOOST_CHECK_EQUAL( int( n ), dpq.getTop() ); dpq.popTop(); } BOOST_CHECK_EQUAL( MAXI, Index( n ) ); BOOST_CHECK( dpq.isEmpty() ); BOOST_CHECK( dpq.checkConsistency() ); }
BOOST_AUTO_TEST_CASE_TEMPLATE( testInterleavedSortingWithPops, DPQ, novolatile ) { DPQ dpq; typedef typename DPQ::Index Index; IDVector idVector; const Index MAXI( 101 ); for( int n( MAXI-1 ); n != 0 ; n-=2 ) { const ID id( dpq.push( n ) ); if( n == 12 || n == 46 ) { idVector.push_back( id ); } } dpq.pop( idVector.back() ); idVector.pop_back(); BOOST_CHECK_EQUAL( MAXI/2 -1, dpq.getSize() ); BOOST_CHECK( dpq.check() ); for( int n( MAXI ); n != -1 ; n-=2 ) { const ID id( dpq.push( n ) ); if( n == 17 || n == 81 ) { idVector.push_back( id ); } } for( IDVector::const_iterator i( idVector.begin() ); i != idVector.end(); ++i ) { dpq.pop( *i ); } BOOST_CHECK( dpq.check() ); BOOST_CHECK_EQUAL( MAXI-4, dpq.getSize() ); int n( 0 ); while( ! dpq.isEmpty() ) { ++n; if( n == 12 || n == 46 || n == 17 || n == 81 ) { continue; } BOOST_CHECK_EQUAL( n, dpq.getTop() ); dpq.popTop(); } BOOST_CHECK_EQUAL( MAXI, Index( n ) ); BOOST_CHECK( dpq.isEmpty() ); BOOST_CHECK( dpq.check() ); }