コード例 #1
0
void tst_Q3ValueVector::begin()
{
    Q3ValueVector<int> a;
    a.push_back( 1 );
    a.push_back( 2 );

    Q3ValueVector<int>::iterator it_a = a.begin();
    QCOMPARE( (*it_a), 1 );

    // now try it for an empty vector; per the documentation begin() should equal end()

    Q3ValueVector<int> b;
    Q3ValueVector<int>::iterator it_b = b.begin();
    QVERIFY( it_b == b.end() );
}
コード例 #2
0
void tst_Q3ValueVector::end()
{
    Q3ValueVector<int> a;
    a.push_back( 1 );
    a.push_back( 2 );

    Q3ValueVector<int>::iterator it_a = a.end();
    QCOMPARE( (*(--it_a)), 2 );

    Q3ValueVector<int> b;
    Q3ValueVector<int>::iterator it_b = b.end();
    QVERIFY( it_b == b.begin() );
}
コード例 #3
0
void tst_Q3ValueVector::insert()
{
    // insert at the beginning
    Q3ValueVector<int> a;
    a.insert( a.begin(), 1 );
    QCOMPARE( a[0], 1 );

    // insert at the end
    a.insert( a.end(), 2 );
    QCOMPARE( a[1], 2 );
    // insert in the middle
    Q3ValueVector<int>::iterator it_a = a.begin();
    a.insert( ++it_a, 3 );
    QCOMPARE( a[1], 3 );

    // now testing the overloaded insert() which takes an
    // argument for the number of items to insert

    // we'll insert two of each value

    Q3ValueVector<int> b;
    b.insert( b.begin(), 2, 1 );
    QCOMPARE( b[0], 1 );
    QCOMPARE( b[1], 1 );

    // insert at the end
    b.insert( b.end(), 2, 2 );
    QCOMPARE( b[2], 2 );
    QCOMPARE( b[3], 2 );

    // insert in the middle
    Q3ValueVector<int>::iterator it_b = b.begin();
    b.insert( ++++it_b, 2, 3 );
    QCOMPARE( b[2], 3 );
    QCOMPARE( b[3], 3 );
}