コード例 #1
0
    void testInterleavedSorting()
    {
        DPQ dpq;

        const Index MAXI( 101 );
        for( int i( MAXI-1 ); i != 0  ; i-=2 )
        {
            dpq.push( i );
        }

        for( int i( MAXI ); i != -1  ; i-=2 )
        {
            dpq.push( i );
        }

        BOOST_CHECK_EQUAL( MAXI, dpq.getSize() );

        BOOST_CHECK( dpq.checkConsistency() );

        int n( 0 );
        while( ! dpq.isEmpty() )
        {
            ++n;
            BOOST_CHECK_EQUAL( n, dpq.getTop() );
            dpq.popTop();
        }

        BOOST_CHECK_EQUAL( MAXI, Index( n ) );

        BOOST_CHECK( dpq.isEmpty() );
        BOOST_CHECK( dpq.checkConsistency() );
    }
コード例 #2
0
    void testConstruction()
    {
        DPQ dpq;

        BOOST_CHECK( dpq.isEmpty() );
        BOOST_CHECK( dpq.checkConsistency() );
    }
コード例 #3
0
BOOST_AUTO_TEST_CASE_TEMPLATE( testInterleavedSorting, DPQ, both )
{
    DPQ dpq;
    typedef typename DPQ::Index Index;

    const Index MAXI( 101 );
    for( int i( MAXI-1 ); i != 0  ; i-=2 )
    {
        dpq.push( i );
    }

    for( int i( MAXI ); i != -1  ; i-=2 )
    {
        dpq.push( i );
    }

    BOOST_CHECK_EQUAL( MAXI, dpq.getSize() );

    BOOST_CHECK( dpq.check() );

    int n( 0 );
    while( ! dpq.isEmpty() )
    {
        ++n;
        BOOST_CHECK_EQUAL( n, dpq.getTop() );
        dpq.popTop();
    }

    BOOST_CHECK_EQUAL( MAXI, Index( n ) );

    BOOST_CHECK( dpq.isEmpty() );
    BOOST_CHECK( dpq.check() );
}
コード例 #4
0
BOOST_AUTO_TEST_CASE_TEMPLATE( testConstruction, DPQ, both )
{
    DPQ dpq;

    BOOST_CHECK( dpq.isEmpty() );
    BOOST_CHECK( dpq.check() );
}
コード例 #5
0
BOOST_AUTO_TEST_CASE_TEMPLATE( testPush, DPQ, both )
{
    DPQ dpq;

    dpq.push( 1 );

    BOOST_CHECK( dpq.check() );
    BOOST_CHECK( dpq.getTop() == 1.0 );
}
コード例 #6
0
    void testPush()
    {
        DPQ dpq;

        dpq.push( 1 );

        BOOST_CHECK( dpq.checkConsistency() );
        BOOST_CHECK( dpq.getTop() == 1.0 );
    }
コード例 #7
0
BOOST_AUTO_TEST_CASE_TEMPLATE( testSecond01, DPQ, both )
{
    DPQ dpq;

    BOOST_CHECK_THROW( dpq.peekSecond(), std::out_of_range );

    dpq.push( 4 );

    BOOST_CHECK_EQUAL( 4, dpq.getTop() );
    BOOST_CHECK_THROW( dpq.peekSecond(), std::out_of_range );
}
コード例 #8
0
    void testSimpleSorting()
    {
        DPQ dpq;

        const int MAXI( 100 );
        for( int i( MAXI ); i != 0  ; --i )
        {
            dpq.push( i );
        }

        BOOST_CHECK( dpq.checkConsistency() );

        int n( 0 );
        while( ! dpq.isEmpty() )
        {
            ++n;
            BOOST_CHECK_EQUAL( n, dpq.getTop() );
            dpq.popTop();
        }

        BOOST_CHECK_EQUAL( MAXI, n );

        BOOST_CHECK( dpq.isEmpty() );
        BOOST_CHECK( dpq.checkConsistency() );
    }
コード例 #9
0
BOOST_AUTO_TEST_CASE_TEMPLATE( testSimpleSorting, DPQ, both )
{
    DPQ dpq;

    const int MAXI( 100 );
    for( int i( MAXI ); i != 0  ; --i )
    {
        dpq.push( i );
    }

    BOOST_CHECK( dpq.check() );

    int n( 0 );
    while( ! dpq.isEmpty() )
    {
        ++n;
        BOOST_CHECK_EQUAL( n, dpq.getTop() );
        dpq.popTop();
    }

    BOOST_CHECK_EQUAL( MAXI, n );

    BOOST_CHECK( dpq.isEmpty() );
    BOOST_CHECK( dpq.check() );
}
コード例 #10
0
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() );
}
コード例 #11
0
BOOST_AUTO_TEST_CASE_TEMPLATE( testSecond2, DPQ, both )
{
    {
        DPQ dpq;

        dpq.push( 1 );
        dpq.push( 4 );

        BOOST_CHECK_EQUAL( 1, dpq.getTop() );
        BOOST_CHECK_EQUAL( 4, dpq.peekSecond() );
    }


    {
        DPQ dpq;

        dpq.push( 4 );
        dpq.push( 1 );

        BOOST_CHECK_EQUAL( 1, dpq.getTop() );
        BOOST_CHECK_EQUAL( 4, dpq.peekSecond() );
    }
}
コード例 #12
0
BOOST_AUTO_TEST_CASE_TEMPLATE( testReplaceTop, DPQ, both )
{
    DPQ dpq;

    dpq.push( 4 );
    dpq.push( 2 );
    dpq.push( 1 );

    BOOST_CHECK_EQUAL( 1, dpq.getTop() );

    dpq.replaceTop( 3 );

    BOOST_CHECK( dpq.check() );
    BOOST_CHECK_EQUAL( 2, dpq.getTop() );

    dpq.popTop();
    BOOST_CHECK_EQUAL( 3, dpq.getTop() );
    dpq.popTop();
    BOOST_CHECK_EQUAL( 4, dpq.getTop() );
    dpq.popTop();


    BOOST_CHECK( dpq.isEmpty() );
    BOOST_CHECK( dpq.check() );
}
コード例 #13
0
BOOST_AUTO_TEST_CASE_TEMPLATE( testClear_manyItems, DPQ, both )
{
    DPQ dpq;
    typedef typename DPQ::Index Index;

    for( int i( 0 ); i < 70000; ++i )
    {
        dpq.push( i );
    }

    BOOST_CHECK( dpq.check() );

    dpq.clear();

    BOOST_CHECK( dpq.isEmpty() );
    BOOST_CHECK( dpq.check() );

    dpq.push( 2 );
    dpq.push( 20 );
    dpq.push( 30 );

    BOOST_CHECK_EQUAL( Index( 3 ), dpq.getSize() );

    dpq.clear();

    BOOST_CHECK( dpq.isEmpty() );
    BOOST_CHECK( dpq.check() );
}
コード例 #14
0
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() );
}
コード例 #15
0
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() );
}
コード例 #16
0
BOOST_AUTO_TEST_CASE_TEMPLATE( testDuplicatedItems, DPQ, both )
{
    DPQ dpq;

    dpq.push( 1 );
    dpq.push( 2 );
    dpq.push( 1 );
    dpq.push( 2 );

    BOOST_CHECK( dpq.check() );

    BOOST_CHECK( dpq.getTop() == 1 );
    dpq.popTop();
    BOOST_CHECK( dpq.getTop() == 1 );
    dpq.popTop();
    BOOST_CHECK( dpq.getTop() == 2 );
    dpq.popTop();
    BOOST_CHECK( dpq.getTop() == 2 );
    dpq.popTop();

    BOOST_CHECK( dpq.isEmpty() );

    BOOST_CHECK( dpq.check() );
}
コード例 #17
0
BOOST_AUTO_TEST_CASE_TEMPLATE( testReplace6, DPQ, both )
{
    DPQ dpq;

    dpq.push( 5 );
    dpq.push( 4 );
    dpq.push( 3 );
    const ID id( dpq.push( 1 ) );
    BOOST_CHECK( dpq.check() );

    BOOST_CHECK_EQUAL( 4, dpq.getSize() );
    BOOST_CHECK_EQUAL( 1, dpq.getTop() );

    dpq.replace( id, 3 );  // 1->3 top down

    BOOST_CHECK( dpq.check() );
    BOOST_CHECK_EQUAL( 4, dpq.getSize() );

    BOOST_CHECK_EQUAL( 3, dpq.getTop() );
    dpq.popTop();
    BOOST_CHECK_EQUAL( 3, dpq.getTop() );
    dpq.popTop();
    BOOST_CHECK_EQUAL( 4, dpq.getTop() );
    dpq.popTop();
    BOOST_CHECK_EQUAL( 5, dpq.getTop() );
    dpq.popTop();

    BOOST_CHECK( dpq.isEmpty() );
    BOOST_CHECK( dpq.check() );
}
コード例 #18
0
    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() );
    }
コード例 #19
0
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() );
}
コード例 #20
0
    void testDuplicatedItems()
    {
        DPQ dpq;

        dpq.push( 1 );
        dpq.push( 2 );
        dpq.push( 1 );
        dpq.push( 2 );

        BOOST_CHECK( dpq.checkConsistency() );

        BOOST_CHECK( dpq.getTop() == 1 );
        dpq.popTop();
        BOOST_CHECK( dpq.getTop() == 1 );
        dpq.popTop();
        BOOST_CHECK( dpq.getTop() == 2 );
        dpq.popTop();
        BOOST_CHECK( dpq.getTop() == 2 );
        dpq.popTop();

        BOOST_CHECK( dpq.isEmpty() );

        BOOST_CHECK( dpq.checkConsistency() );
    }
コード例 #21
0
    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() );
    }
コード例 #22
0
    void testClearManyItems()
    {
        DPQ dpq;
        typedef typename DPQ::Index Index;

        for( int i( 0 ); i < 70000; ++i )
        {
            dpq.push( i );
        }

        BOOST_CHECK( dpq.checkConsistency() );

        dpq.clear();

        BOOST_CHECK( dpq.isEmpty() );
        BOOST_CHECK( dpq.checkConsistency() );

        dpq.push( 2 );
        dpq.push( 20 );
        dpq.push( 30 );

        BOOST_CHECK_EQUAL( Index( 3 ), dpq.getSize() );

        dpq.clear();

        BOOST_CHECK( dpq.isEmpty() );
        BOOST_CHECK( dpq.checkConsistency() );
    }
コード例 #23
0
    void testClear()
    {
        DPQ dpq;

        dpq.push( 1 );
        dpq.push( 20 );
        dpq.push( 50 );

        BOOST_CHECK_EQUAL( Index( 3 ), dpq.getSize() );

        dpq.clear();

        BOOST_CHECK( dpq.isEmpty() );
        BOOST_CHECK( dpq.checkConsistency() );

        dpq.push( 2 );
        dpq.push( 20 );
        dpq.push( 30 );

        BOOST_CHECK_EQUAL( Index( 3 ), dpq.getSize() );

        dpq.clear();

        BOOST_CHECK( dpq.isEmpty() );
        BOOST_CHECK( dpq.checkConsistency() );
    }
コード例 #24
0
    void testReplaceTop()
    {
        DPQ dpq;

        dpq.push( 4 );
        dpq.push( 2 );
        dpq.push( 1 );

        BOOST_CHECK_EQUAL( 1, dpq.getTop() );

        dpq.replaceTop( 3 );

        BOOST_CHECK( dpq.checkConsistency() );
        BOOST_CHECK_EQUAL( 2, dpq.getTop() );

        dpq.popTop();
        BOOST_CHECK_EQUAL( 3, dpq.getTop() );
        dpq.popTop();
        BOOST_CHECK_EQUAL( 4, dpq.getTop() );
        dpq.popTop();


        BOOST_CHECK( dpq.isEmpty() );
        BOOST_CHECK( dpq.checkConsistency() );
    }
コード例 #25
0
BOOST_AUTO_TEST_CASE_TEMPLATE( testClear, DPQ, both )
{
    DPQ dpq;
    typedef typename DPQ::Index Index;

    dpq.push( 1 );
    dpq.push( 20 );
    dpq.push( 50 );

    BOOST_CHECK_EQUAL( Index( 3 ), dpq.getSize() );

    dpq.clear();

    BOOST_CHECK( dpq.isEmpty() );
    BOOST_CHECK( dpq.check() );

    dpq.push( 2 );
    dpq.push( 20 );
    dpq.push( 30 );

    BOOST_CHECK_EQUAL( Index( 3 ), dpq.getSize() );

    dpq.clear();

    BOOST_CHECK( dpq.isEmpty() );
    BOOST_CHECK( dpq.check() );
}
コード例 #26
0
    void testReplace()
    {
        DPQ dpq;

        dpq.push( 5 );
        const Index id( dpq.push( 4 ) );
        dpq.push( 3 );
        dpq.push( 1 );

        BOOST_CHECK_EQUAL( 1, dpq.getTop() );

        dpq.replace( id, 2 );  // 4->2

        BOOST_CHECK( dpq.checkConsistency() );
        BOOST_CHECK_EQUAL( 1, dpq.getTop() );

        dpq.popTop();
        BOOST_CHECK_EQUAL( 2, dpq.getTop() );
        dpq.popTop();
        BOOST_CHECK_EQUAL( 3, dpq.getTop() );
        dpq.popTop();
        BOOST_CHECK_EQUAL( 5, dpq.getTop() );
        dpq.popTop();

        BOOST_CHECK( dpq.isEmpty() );
        BOOST_CHECK( dpq.checkConsistency() );
    }