822 lines
19 KiB
C++
822 lines
19 KiB
C++
#include <ebcl/Arrays.hh>
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
using namespace ebcl;
|
|
|
|
|
|
class ArraysIterTest : public CppUnit::TestFixture
|
|
{
|
|
CPPUNIT_TEST_SUITE( ArraysIterTest );
|
|
CPPUNIT_TEST( testConstructDefault );
|
|
CPPUNIT_TEST( testConstructFromArray );
|
|
CPPUNIT_TEST( testCopyCons );
|
|
CPPUNIT_TEST( testCopyAss );
|
|
CPPUNIT_TEST( testSwap );
|
|
|
|
CPPUNIT_TEST( testArrayIterator );
|
|
CPPUNIT_TEST( testArrayReverse );
|
|
|
|
CPPUNIT_TEST( testDerefStar );
|
|
CPPUNIT_TEST( testDerefArrow );
|
|
CPPUNIT_TEST( testDerefOffset );
|
|
|
|
CPPUNIT_TEST( testCmpEq );
|
|
CPPUNIT_TEST( testCmpNe );
|
|
CPPUNIT_TEST( testCmpLt );
|
|
CPPUNIT_TEST( testCmpLe );
|
|
CPPUNIT_TEST( testCmpGt );
|
|
CPPUNIT_TEST( testCmpGe );
|
|
|
|
CPPUNIT_TEST( testPreIncrement );
|
|
CPPUNIT_TEST( testPostIncrement );
|
|
CPPUNIT_TEST( testPreDecrement );
|
|
CPPUNIT_TEST( testPostDecrement );
|
|
|
|
CPPUNIT_TEST( testPreIncrementReverse );
|
|
CPPUNIT_TEST( testPostIncrementReverse );
|
|
CPPUNIT_TEST( testPreDecrementReverse );
|
|
CPPUNIT_TEST( testPostDecrementReverse );
|
|
|
|
CPPUNIT_TEST( testAddTo );
|
|
CPPUNIT_TEST( testAddToReverse );
|
|
CPPUNIT_TEST( testSubTo );
|
|
CPPUNIT_TEST( testSubToReverse );
|
|
|
|
CPPUNIT_TEST( testAdd );
|
|
CPPUNIT_TEST( testAddReverse );
|
|
CPPUNIT_TEST( testSub );
|
|
CPPUNIT_TEST( testSubReverse );
|
|
CPPUNIT_TEST( testDifference );
|
|
CPPUNIT_TEST_SUITE_END( );
|
|
|
|
public:
|
|
void testConstructDefault( );
|
|
void testConstructFromArray( );
|
|
void testCopyCons( );
|
|
void testCopyAss( );
|
|
void testSwap( );
|
|
|
|
void testArrayIterator( );
|
|
void testArrayReverse( );
|
|
|
|
void testDerefStar( );
|
|
void testDerefArrow( );
|
|
void testDerefOffset( );
|
|
|
|
void testCmpEq( );
|
|
void testCmpNe( );
|
|
void testCmpLt( );
|
|
void testCmpLe( );
|
|
void testCmpGt( );
|
|
void testCmpGe( );
|
|
|
|
void testPreIncrement( );
|
|
void testPostIncrement( );
|
|
void testPreDecrement( );
|
|
void testPostDecrement( );
|
|
|
|
void testPreIncrementReverse( );
|
|
void testPostIncrementReverse( );
|
|
void testPreDecrementReverse( );
|
|
void testPostDecrementReverse( );
|
|
|
|
void testAddTo( );
|
|
void testAddToReverse( );
|
|
void testSubTo( );
|
|
void testSubToReverse( );
|
|
|
|
void testAdd( );
|
|
void testAddReverse( );
|
|
void testSub( );
|
|
void testSubReverse( );
|
|
void testDifference( );
|
|
};
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( ArraysIterTest );
|
|
|
|
using T_Test_ = T_Array< int >;
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
void ArraysIterTest::testConstructDefault( )
|
|
{
|
|
T_Test_::T_Iterator iter;
|
|
CPPUNIT_ASSERT( !iter.valid( ) );
|
|
}
|
|
|
|
void ArraysIterTest::testConstructFromArray( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
|
|
T_Test_::T_Iterator iter( x , 1 );
|
|
CPPUNIT_ASSERT( iter.valid( ) );
|
|
CPPUNIT_ASSERT( iter.target( ) == &x );
|
|
CPPUNIT_ASSERT( iter.pos( ) == 1 );
|
|
}
|
|
|
|
void ArraysIterTest::testCopyCons( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
|
|
T_Test_::T_Iterator iter( x , 1 );
|
|
T_Test_::T_Iterator iter2( iter );
|
|
iter = {};
|
|
|
|
CPPUNIT_ASSERT( iter2.valid( ) );
|
|
CPPUNIT_ASSERT( iter2.target( ) == &x );
|
|
CPPUNIT_ASSERT( iter2.pos( ) == 1 );
|
|
}
|
|
|
|
void ArraysIterTest::testCopyAss( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
|
|
T_Test_::T_Iterator iter( x , 1 );
|
|
T_Test_::T_Iterator iter2;
|
|
iter2 = iter;
|
|
iter = {};
|
|
|
|
CPPUNIT_ASSERT( iter2.valid( ) );
|
|
CPPUNIT_ASSERT( iter2.target( ) == &x );
|
|
CPPUNIT_ASSERT( iter2.pos( ) == 1 );
|
|
}
|
|
|
|
void ArraysIterTest::testSwap( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
|
|
T_Test_::T_Iterator iter( x , 1 );
|
|
T_Test_::T_Iterator iter2;
|
|
swap( iter , iter2 );
|
|
|
|
CPPUNIT_ASSERT( !iter.valid( ) );
|
|
CPPUNIT_ASSERT( iter.target( ) == nullptr );
|
|
CPPUNIT_ASSERT( iter.pos( ) == 0 );
|
|
|
|
CPPUNIT_ASSERT( iter2.valid( ) );
|
|
CPPUNIT_ASSERT( iter2.target( ) == &x );
|
|
CPPUNIT_ASSERT( iter2.pos( ) == 1 );
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
void ArraysIterTest::testArrayIterator( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
|
|
T_Test_::T_Iterator it1( x.begin( ) );
|
|
T_Test_::T_Iterator it2( x.end( ) );
|
|
|
|
CPPUNIT_ASSERT( &x == it1.target( ) );
|
|
CPPUNIT_ASSERT( &x == it2.target( ) );
|
|
|
|
CPPUNIT_ASSERT( 0 == it1.pos( ) );
|
|
CPPUNIT_ASSERT( x.size( ) == it2.pos( ) );
|
|
}
|
|
|
|
void ArraysIterTest::testArrayReverse( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
|
|
T_Test_::T_ReverseIterator it1( x.rbegin( ) );
|
|
T_Test_::T_ReverseIterator it2( x.rend( ) );
|
|
|
|
CPPUNIT_ASSERT( &x == it1.target( ) );
|
|
CPPUNIT_ASSERT( &x == it2.target( ) );
|
|
|
|
CPPUNIT_ASSERT( x.size( ) - 1 == it1.pos( ) );
|
|
CPPUNIT_ASSERT( -1 == it2.pos( ) );
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
void ArraysIterTest::testDerefStar( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
|
|
T_Test_::T_Iterator it( x , 0 );
|
|
CPPUNIT_ASSERT_EQUAL( 1 , *it );
|
|
}
|
|
|
|
void ArraysIterTest::testDerefArrow( )
|
|
{
|
|
struct T_Obj_ {
|
|
int x;
|
|
T_Obj_( int x ) : x( x ) { }
|
|
int value( ) const noexcept { return x; }
|
|
};
|
|
using T_Test_ = T_Array< T_Obj_ >;
|
|
|
|
T_Test_ t;
|
|
t.add( 42 );
|
|
|
|
T_Test_::T_Iterator it( t , 0 );
|
|
CPPUNIT_ASSERT_EQUAL( 42 , it->value( ) );
|
|
}
|
|
|
|
void ArraysIterTest::testDerefOffset( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 0 );
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
|
|
T_Test_::T_Iterator it( x , 1 );
|
|
CPPUNIT_ASSERT_EQUAL( 0 , it[ -1 ] );
|
|
CPPUNIT_ASSERT_EQUAL( 1 , it[ 0 ] );
|
|
CPPUNIT_ASSERT_EQUAL( 2 , it[ 1 ] );
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
void ArraysIterTest::testCmpEq( )
|
|
{
|
|
T_Test_ x , x2;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x2.add( 3 );
|
|
|
|
T_Test_::T_Iterator iter1( x , 0 ) ,
|
|
iter2( x , 0 ) ,
|
|
iter3 ,
|
|
iter4( x , 1 ) ,
|
|
iter5 ,
|
|
iter6( x2 , 0 );
|
|
|
|
CPPUNIT_ASSERT( iter1 == iter1 );
|
|
CPPUNIT_ASSERT( iter1 == iter2 );
|
|
CPPUNIT_ASSERT( !( iter1 == iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter1 == iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter1 == iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter1 == iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( iter2 == iter1 );
|
|
CPPUNIT_ASSERT( iter2 == iter2 );
|
|
CPPUNIT_ASSERT( !( iter2 == iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter2 == iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter2 == iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter2 == iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter3 == iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter3 == iter2 ) );
|
|
CPPUNIT_ASSERT( iter3 == iter3 );
|
|
CPPUNIT_ASSERT( !( iter3 == iter4 ) );
|
|
CPPUNIT_ASSERT( iter3 == iter5 );
|
|
CPPUNIT_ASSERT( !( iter3 == iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter4 == iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter4 == iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter4 == iter3 ) );
|
|
CPPUNIT_ASSERT( iter4 == iter4 );
|
|
CPPUNIT_ASSERT( !( iter4 == iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter4 == iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter5 == iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter5 == iter2 ) );
|
|
CPPUNIT_ASSERT( iter5 == iter3 );
|
|
CPPUNIT_ASSERT( !( iter5 == iter4 ) );
|
|
CPPUNIT_ASSERT( iter5 == iter5 );
|
|
CPPUNIT_ASSERT( !( iter5 == iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter6 == iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter6 == iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter6 == iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter6 == iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter6 == iter5 ) );
|
|
CPPUNIT_ASSERT( iter6 == iter6 );
|
|
}
|
|
|
|
void ArraysIterTest::testCmpNe( )
|
|
{
|
|
T_Test_ x , x2;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x2.add( 3 );
|
|
|
|
T_Test_::T_Iterator iter1( x , 0 ) ,
|
|
iter2( x , 0 ) ,
|
|
iter3 ,
|
|
iter4( x , 1 ) ,
|
|
iter5 ,
|
|
iter6( x2 , 0 );
|
|
|
|
CPPUNIT_ASSERT( !( iter1 != iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter1 != iter2 ) );
|
|
CPPUNIT_ASSERT( iter1 != iter3 );
|
|
CPPUNIT_ASSERT( iter1 != iter4 );
|
|
CPPUNIT_ASSERT( iter1 != iter5 );
|
|
CPPUNIT_ASSERT( iter1 != iter6 );
|
|
|
|
CPPUNIT_ASSERT( !( iter2 != iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter2 != iter2 ) );
|
|
CPPUNIT_ASSERT( iter2 != iter3 );
|
|
CPPUNIT_ASSERT( iter2 != iter4 );
|
|
CPPUNIT_ASSERT( iter2 != iter5 );
|
|
CPPUNIT_ASSERT( iter2 != iter6 );
|
|
|
|
CPPUNIT_ASSERT( iter3 != iter1 );
|
|
CPPUNIT_ASSERT( iter3 != iter2 );
|
|
CPPUNIT_ASSERT( !( iter3 != iter3 ) );
|
|
CPPUNIT_ASSERT( iter3 != iter4 );
|
|
CPPUNIT_ASSERT( !( iter3 != iter5 ) );
|
|
CPPUNIT_ASSERT( iter3 != iter6 );
|
|
|
|
CPPUNIT_ASSERT( iter4 != iter1 );
|
|
CPPUNIT_ASSERT( iter4 != iter2 );
|
|
CPPUNIT_ASSERT( iter4 != iter3 );
|
|
CPPUNIT_ASSERT( !( iter4 != iter4 ) );
|
|
CPPUNIT_ASSERT( iter4 != iter5 );
|
|
CPPUNIT_ASSERT( iter4 != iter6 );
|
|
|
|
CPPUNIT_ASSERT( iter5 != iter1 );
|
|
CPPUNIT_ASSERT( iter5 != iter2 );
|
|
CPPUNIT_ASSERT( !( iter5 != iter3 ) );
|
|
CPPUNIT_ASSERT( iter5 != iter4 );
|
|
CPPUNIT_ASSERT( !( iter5 != iter5 ) );
|
|
CPPUNIT_ASSERT( iter5 != iter6 );
|
|
|
|
CPPUNIT_ASSERT( iter6 != iter1 );
|
|
CPPUNIT_ASSERT( iter6 != iter2 );
|
|
CPPUNIT_ASSERT( iter6 != iter3 );
|
|
CPPUNIT_ASSERT( iter6 != iter4 );
|
|
CPPUNIT_ASSERT( iter6 != iter5 );
|
|
CPPUNIT_ASSERT( !( iter6 != iter6 ) );
|
|
}
|
|
|
|
void ArraysIterTest::testCmpLt( )
|
|
{
|
|
T_Test_ x , x2;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x2.add( 3 );
|
|
|
|
T_Test_::T_Iterator iter1( x , 0 ) ,
|
|
iter2( x , 0 ) ,
|
|
iter3 ,
|
|
iter4( x , 1 ) ,
|
|
iter5 ,
|
|
iter6( x2 , 0 );
|
|
|
|
CPPUNIT_ASSERT( !( iter1 < iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter1 < iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter1 < iter3 ) );
|
|
CPPUNIT_ASSERT( iter1 < iter4 );
|
|
CPPUNIT_ASSERT( !( iter1 < iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter1 < iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter2 < iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter2 < iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter2 < iter3 ) );
|
|
CPPUNIT_ASSERT( iter2 < iter4 );
|
|
CPPUNIT_ASSERT( !( iter2 < iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter2 < iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter3 < iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter3 < iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter3 < iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter3 < iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter3 < iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter3 < iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter4 < iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter4 < iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter4 < iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter4 < iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter4 < iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter4 < iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter5 < iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter5 < iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter5 < iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter5 < iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter5 < iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter5 < iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter6 < iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter6 < iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter6 < iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter6 < iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter6 < iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter6 < iter6 ) );
|
|
}
|
|
|
|
void ArraysIterTest::testCmpLe( )
|
|
{
|
|
T_Test_ x , x2;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x2.add( 3 );
|
|
|
|
T_Test_::T_Iterator iter1( x , 0 ) ,
|
|
iter2( x , 0 ) ,
|
|
iter3 ,
|
|
iter4( x , 1 ) ,
|
|
iter5 ,
|
|
iter6( x2 , 0 );
|
|
|
|
CPPUNIT_ASSERT( iter1 <= iter1 );
|
|
CPPUNIT_ASSERT( iter1 <= iter2 );
|
|
CPPUNIT_ASSERT( !( iter1 <= iter3 ) );
|
|
CPPUNIT_ASSERT( iter1 <= iter4 );
|
|
CPPUNIT_ASSERT( !( iter1 <= iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter1 <= iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( iter2 <= iter1 );
|
|
CPPUNIT_ASSERT( iter2 <= iter2 );
|
|
CPPUNIT_ASSERT( !( iter2 <= iter3 ) );
|
|
CPPUNIT_ASSERT( iter2 <= iter4 );
|
|
CPPUNIT_ASSERT( !( iter2 <= iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter2 <= iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter3 <= iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter3 <= iter2 ) );
|
|
CPPUNIT_ASSERT( iter3 <= iter3 );
|
|
CPPUNIT_ASSERT( !( iter3 <= iter4 ) );
|
|
CPPUNIT_ASSERT( iter3 <= iter5 );
|
|
CPPUNIT_ASSERT( !( iter3 <= iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter4 <= iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter4 <= iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter4 <= iter3 ) );
|
|
CPPUNIT_ASSERT( iter4 <= iter4 );
|
|
CPPUNIT_ASSERT( !( iter4 <= iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter4 <= iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter5 <= iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter5 <= iter2 ) );
|
|
CPPUNIT_ASSERT( iter5 <= iter3 );
|
|
CPPUNIT_ASSERT( !( iter5 <= iter4 ) );
|
|
CPPUNIT_ASSERT( iter5 <= iter5 );
|
|
CPPUNIT_ASSERT( !( iter5 <= iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter6 <= iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter6 <= iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter6 <= iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter6 <= iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter6 <= iter5 ) );
|
|
CPPUNIT_ASSERT( iter6 <= iter6 );
|
|
}
|
|
|
|
void ArraysIterTest::testCmpGt( )
|
|
{
|
|
T_Test_ x , x2;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x2.add( 3 );
|
|
|
|
T_Test_::T_Iterator iter1( x , 0 ) ,
|
|
iter2( x , 0 ) ,
|
|
iter3 ,
|
|
iter4( x , 1 ) ,
|
|
iter5 ,
|
|
iter6( x2 , 0 );
|
|
|
|
CPPUNIT_ASSERT( !( iter1 > iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter1 > iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter1 > iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter1 > iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter1 > iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter1 > iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter2 > iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter2 > iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter2 > iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter2 > iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter2 > iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter2 > iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter3 > iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter3 > iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter3 > iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter3 > iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter3 > iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter3 > iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( iter4 > iter1 );
|
|
CPPUNIT_ASSERT( iter4 > iter2 );
|
|
CPPUNIT_ASSERT( !( iter4 > iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter4 > iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter4 > iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter4 > iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter5 > iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter5 > iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter5 > iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter5 > iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter5 > iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter5 > iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter6 > iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter6 > iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter6 > iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter6 > iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter6 > iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter6 > iter6 ) );
|
|
}
|
|
|
|
void ArraysIterTest::testCmpGe( )
|
|
{
|
|
T_Test_ x , x2;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x2.add( 3 );
|
|
|
|
T_Test_::T_Iterator iter1( x , 0 ) ,
|
|
iter2( x , 0 ) ,
|
|
iter3 ,
|
|
iter4( x , 1 ) ,
|
|
iter5 ,
|
|
iter6( x2 , 0 );
|
|
|
|
CPPUNIT_ASSERT( iter1 >= iter1 );
|
|
CPPUNIT_ASSERT( iter1 >= iter2 );
|
|
CPPUNIT_ASSERT( !( iter1 >= iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter1 >= iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter1 >= iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter1 >= iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( iter2 >= iter1 );
|
|
CPPUNIT_ASSERT( iter2 >= iter2 );
|
|
CPPUNIT_ASSERT( !( iter2 >= iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter2 >= iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter2 >= iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter2 >= iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter3 >= iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter3 >= iter2 ) );
|
|
CPPUNIT_ASSERT( iter3 >= iter3 );
|
|
CPPUNIT_ASSERT( !( iter3 >= iter4 ) );
|
|
CPPUNIT_ASSERT( iter3 >= iter5 );
|
|
CPPUNIT_ASSERT( !( iter3 >= iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( iter4 >= iter1 );
|
|
CPPUNIT_ASSERT( iter4 >= iter2 );
|
|
CPPUNIT_ASSERT( !( iter4 >= iter3 ) );
|
|
CPPUNIT_ASSERT( iter4 >= iter4 );
|
|
CPPUNIT_ASSERT( !( iter4 >= iter5 ) );
|
|
CPPUNIT_ASSERT( !( iter4 >= iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter5 >= iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter5 >= iter2 ) );
|
|
CPPUNIT_ASSERT( iter5 >= iter3 );
|
|
CPPUNIT_ASSERT( !( iter5 >= iter4 ) );
|
|
CPPUNIT_ASSERT( iter5 >= iter5 );
|
|
CPPUNIT_ASSERT( !( iter5 >= iter6 ) );
|
|
|
|
CPPUNIT_ASSERT( !( iter6 >= iter1 ) );
|
|
CPPUNIT_ASSERT( !( iter6 >= iter2 ) );
|
|
CPPUNIT_ASSERT( !( iter6 >= iter3 ) );
|
|
CPPUNIT_ASSERT( !( iter6 >= iter4 ) );
|
|
CPPUNIT_ASSERT( !( iter6 >= iter5 ) );
|
|
CPPUNIT_ASSERT( iter6 >= iter6 );
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
void ArraysIterTest::testPreIncrement( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
|
|
T_Test_::T_Iterator iter1( x , 0 );
|
|
T_Test_::T_Iterator iter2( ++iter1 );
|
|
|
|
CPPUNIT_ASSERT( iter1.pos( ) == 1 );
|
|
CPPUNIT_ASSERT( iter2.pos( ) == 1 );
|
|
}
|
|
|
|
void ArraysIterTest::testPostIncrement( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
|
|
T_Test_::T_Iterator iter1( x , 0 );
|
|
T_Test_::T_Iterator iter2( iter1++ );
|
|
|
|
CPPUNIT_ASSERT( iter1.pos( ) == 1 );
|
|
CPPUNIT_ASSERT( iter2.pos( ) == 0 );
|
|
}
|
|
|
|
void ArraysIterTest::testPreDecrement( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
|
|
T_Test_::T_Iterator iter1( x , 1 );
|
|
T_Test_::T_Iterator iter2( --iter1 );
|
|
|
|
CPPUNIT_ASSERT( iter1.pos( ) == 0 );
|
|
CPPUNIT_ASSERT( iter2.pos( ) == 0 );
|
|
}
|
|
|
|
void ArraysIterTest::testPostDecrement( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
|
|
T_Test_::T_Iterator iter1( x , 1 );
|
|
T_Test_::T_Iterator iter2( iter1-- );
|
|
|
|
CPPUNIT_ASSERT( iter1.pos( ) == 0 );
|
|
CPPUNIT_ASSERT( iter2.pos( ) == 1 );
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
void ArraysIterTest::testPreIncrementReverse( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
|
|
T_Test_::T_ReverseIterator iter1( x , 1 );
|
|
T_Test_::T_ReverseIterator iter2( ++iter1 );
|
|
|
|
CPPUNIT_ASSERT( iter1.pos( ) == 0 );
|
|
CPPUNIT_ASSERT( iter2.pos( ) == 0 );
|
|
}
|
|
|
|
void ArraysIterTest::testPostIncrementReverse( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
|
|
T_Test_::T_ReverseIterator iter1( x , 1 );
|
|
T_Test_::T_ReverseIterator iter2( iter1++ );
|
|
|
|
CPPUNIT_ASSERT( iter1.pos( ) == 0 );
|
|
CPPUNIT_ASSERT( iter2.pos( ) == 1 );
|
|
}
|
|
|
|
void ArraysIterTest::testPreDecrementReverse( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
|
|
T_Test_::T_ReverseIterator iter1( x , 0 );
|
|
T_Test_::T_ReverseIterator iter2( --iter1 );
|
|
|
|
CPPUNIT_ASSERT( iter1.pos( ) == 1 );
|
|
CPPUNIT_ASSERT( iter2.pos( ) == 1 );
|
|
}
|
|
|
|
void ArraysIterTest::testPostDecrementReverse( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
|
|
T_Test_::T_ReverseIterator iter1( x , 0 );
|
|
T_Test_::T_ReverseIterator iter2( iter1-- );
|
|
|
|
CPPUNIT_ASSERT( iter1.pos( ) == 1 );
|
|
CPPUNIT_ASSERT( iter2.pos( ) == 0 );
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
void ArraysIterTest::testAddTo( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x.add( 3 );
|
|
|
|
T_Test_::T_Iterator it( x , 0 );
|
|
it += 2;
|
|
CPPUNIT_ASSERT( it.pos( ) == 2 );
|
|
it += 2;
|
|
CPPUNIT_ASSERT( it.pos( ) == 3 );
|
|
}
|
|
|
|
void ArraysIterTest::testAddToReverse( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x.add( 3 );
|
|
|
|
T_Test_::T_ReverseIterator it( x.rbegin( ) );
|
|
it += 2;
|
|
CPPUNIT_ASSERT( it.pos( ) == 0 );
|
|
it += 2;
|
|
CPPUNIT_ASSERT( it.pos( ) == -1 );
|
|
}
|
|
|
|
void ArraysIterTest::testSubTo( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x.add( 3 );
|
|
|
|
T_Test_::T_Iterator it( x , x.size( ) - 1 );
|
|
it -= 2;
|
|
CPPUNIT_ASSERT( it.pos( ) == 0 );
|
|
it -= 2;
|
|
CPPUNIT_ASSERT( it.pos( ) == -1 );
|
|
}
|
|
|
|
void ArraysIterTest::testSubToReverse( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x.add( 3 );
|
|
|
|
T_Test_::T_ReverseIterator it( x , 0 );
|
|
it -= 2;
|
|
CPPUNIT_ASSERT( it.pos( ) == 2 );
|
|
it -= 2;
|
|
CPPUNIT_ASSERT( it.pos( ) == 3 );
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
void ArraysIterTest::testAdd( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x.add( 3 );
|
|
|
|
T_Test_::T_Iterator it( x , 0 );
|
|
auto it2( it + 4 );
|
|
CPPUNIT_ASSERT( it.pos( ) == 0 );
|
|
CPPUNIT_ASSERT( it2.target( ) == &x );
|
|
CPPUNIT_ASSERT( it2.pos( ) == 3 );
|
|
CPPUNIT_ASSERT( it2 == x.end( ) );
|
|
}
|
|
|
|
void ArraysIterTest::testAddReverse( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x.add( 3 );
|
|
|
|
T_Test_::T_ReverseIterator it( x.rbegin( ) );
|
|
auto it2( it + 4 );
|
|
CPPUNIT_ASSERT( it.pos( ) == 2 );
|
|
CPPUNIT_ASSERT( it2.target( ) == &x );
|
|
CPPUNIT_ASSERT( it2.pos( ) == -1 );
|
|
CPPUNIT_ASSERT( it2 == x.rend( ) );
|
|
}
|
|
|
|
void ArraysIterTest::testSub( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x.add( 3 );
|
|
|
|
T_Test_::T_Iterator it( x , x.size( ) - 1 );
|
|
auto it2( it - 4 );
|
|
CPPUNIT_ASSERT( it.pos( ) == 2 );
|
|
CPPUNIT_ASSERT( it2.target( ) == &x );
|
|
CPPUNIT_ASSERT( it2.pos( ) == -1 );
|
|
}
|
|
|
|
void ArraysIterTest::testSubReverse( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x.add( 3 );
|
|
|
|
T_Test_::T_ReverseIterator it( x , 0 );
|
|
auto it2( it - 4 );
|
|
CPPUNIT_ASSERT( it.pos( ) == 0 );
|
|
CPPUNIT_ASSERT( it2.target( ) == &x );
|
|
CPPUNIT_ASSERT( it2.pos( ) == 3 );
|
|
}
|
|
|
|
void ArraysIterTest::testDifference( )
|
|
{
|
|
T_Test_ x;
|
|
x.add( 1 );
|
|
x.add( 2 );
|
|
x.add( 3 );
|
|
|
|
T_Test_::T_Iterator it( x.begin( ) );
|
|
T_Test_::T_Iterator it2( x.end( ) );
|
|
const auto diff1( it2 - it );
|
|
CPPUNIT_ASSERT( diff1 == x.size( ) );
|
|
const auto diff2( it - it2 );
|
|
CPPUNIT_ASSERT( -diff2 == x.size( ) );
|
|
}
|