本文整理汇总了C++中SimpleList::size方法的典型用法代码示例。如果您正苦于以下问题:C++ SimpleList::size方法的具体用法?C++ SimpleList::size怎么用?C++ SimpleList::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleList
的用法示例。
在下文中一共展示了SimpleList::size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testRemove
void AbstractSequentialListTest::testRemove() {
SimpleList<int> list;
list.add(1);
CPPUNIT_ASSERT_EQUAL( 1, list.removeAt( 0 ) );
list.add( 2 );
CPPUNIT_ASSERT_EQUAL( 2, list.removeAt( 0 ) );
// remove index is out of bounds
try {
list.removeAt( list.size() );
CPPUNIT_FAIL("Should throw IndexOutOfBoundsException.");
} catch( IndexOutOfBoundsException& e ) {
// expected
}
try {
list.removeAt( -1 );
CPPUNIT_FAIL("Should throw IndexOutOfBoundsException.");
} catch( IndexOutOfBoundsException& e ) {
// expected
}
// list dont't support remove operation
try {
MockAbstractSequentialList<int> mylist;
mylist.removeAt( 0 );
CPPUNIT_FAIL("Should throw UnsupportedOperationException.");
} catch( UnsupportedOperationException& e ) {
// expected
}
}
示例2: testGet
void AbstractSequentialListTest::testGet() {
SimpleList<int> list;
list.add( 1 );
list.add( 2 );
CPPUNIT_ASSERT_EQUAL( 1, list.get( 0 ) );
CPPUNIT_ASSERT_EQUAL( 2, list.get( 1 ) );
// get value by index which is out of bounds
try {
list.get( list.size() );
CPPUNIT_FAIL("Should throw IndexOutOfBoundsException.");
} catch( IndexOutOfBoundsException& e ) {
// expected
}
try {
list.get( -1 );
CPPUNIT_FAIL("Should throw IndexOutOfBoundsException.");
} catch( IndexOutOfBoundsException& e ) {
// expected
}
}
示例3: testLastIndexOf
void AbstractListTest::testLastIndexOf() {
SimpleList<int> array;
for( int i = 1; i < 6; i++ ) {
array.add(i);
}
for( int i = 5; i > 0; i-- ) {
array.add(i);
}
CPPUNIT_ASSERT( array.size() == 10 );
MockArrayList<int> list;
list.addAll( array );
CPPUNIT_ASSERT( list.size() == 10 );
CPPUNIT_ASSERT_EQUAL_MESSAGE( "find 6 in the list do not contain 6",
-1, list.lastIndexOf( 6 ) );
CPPUNIT_ASSERT_EQUAL_MESSAGE( "did not return the right location of element 4",
6, list.lastIndexOf( 4 ) );
}