X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0287ae5c754c6d6f573f1980954f278c6120bff2..afab8b85c4bdeb11a248c57d13e9bcfa14149ef8:/tests/arrays/arrays.cpp diff --git a/tests/arrays/arrays.cpp b/tests/arrays/arrays.cpp index 8d32cf2a1f..0ac0ec195f 100644 --- a/tests/arrays/arrays.cpp +++ b/tests/arrays/arrays.cpp @@ -3,7 +3,6 @@ // Purpose: wxArray unit test // Author: Vadim Zeitlin, Wlodzimierz ABX Skiba // Created: 2004-04-01 -// RCS-ID: $Id$ // Copyright: (c) 2004 Vadim Zeitlin, Wlodzimierz Skiba /////////////////////////////////////////////////////////////////////////////// @@ -173,6 +172,7 @@ private: CPPUNIT_TEST( Alloc ); CPPUNIT_TEST( Clear ); CPPUNIT_TEST( Swap ); + CPPUNIT_TEST( IndexFromEnd ); CPPUNIT_TEST_SUITE_END(); void wxStringArrayTest(); @@ -188,6 +188,7 @@ private: void Alloc(); void Clear(); void Swap(); + void IndexFromEnd(); DECLARE_NO_COPY_CLASS(ArraysTestCase) }; @@ -195,7 +196,7 @@ private: // register in the unnamed registry so that these tests are run by default CPPUNIT_TEST_SUITE_REGISTRATION( ArraysTestCase ); -// also include in it's own registry so that these tests can be run alone +// also include in its own registry so that these tests can be run alone CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ArraysTestCase, "ArraysTestCase" ); void ArraysTestCase::wxStringArrayTest() @@ -307,6 +308,13 @@ void ArraysTestCase::wxStringArrayTest() CPPUNIT_ASSERT( a1.Index( wxT("thermit") ) == 3 ); CPPUNIT_ASSERT( a1.Index( wxT("alligator") ) == 4 ); + CPPUNIT_ASSERT( a1.Index( wxT("dog"), /*bCase=*/true, /*fromEnd=*/true ) == 0 ); + CPPUNIT_ASSERT( a1.Index( wxT("human"), /*bCase=*/true, /*fromEnd=*/true ) == 1 ); + CPPUNIT_ASSERT( a1.Index( wxT("humann"), /*bCase=*/true, /*fromEnd=*/true ) == wxNOT_FOUND ); + CPPUNIT_ASSERT( a1.Index( wxT("condor"), /*bCase=*/true, /*fromEnd=*/true ) == 2 ); + CPPUNIT_ASSERT( a1.Index( wxT("thermit"), /*bCase=*/true, /*fromEnd=*/true ) == 3 ); + CPPUNIT_ASSERT( a1.Index( wxT("alligator"), /*bCase=*/true, /*fromEnd=*/true ) == 4 ); + wxArrayString a5; CPPUNIT_ASSERT( a5.Add( wxT("x"), 1 ) == 0 ); @@ -706,3 +714,18 @@ void ArraysTestCase::TestSTL() CPPUNIT_ASSERT_EQUAL( 17, (*(items.rbegin()))->n ); CPPUNIT_ASSERT_EQUAL( 17, (**items.begin()).n ); } + +void ArraysTestCase::IndexFromEnd() +{ + wxArrayInt a; + a.push_back(10); + a.push_back(1); + a.push_back(42); + + CPPUNIT_ASSERT_EQUAL( 0, a.Index(10) ); + CPPUNIT_ASSERT_EQUAL( 1, a.Index(1) ); + CPPUNIT_ASSERT_EQUAL( 2, a.Index(42) ); + CPPUNIT_ASSERT_EQUAL( 0, a.Index(10, /*bFromEnd=*/true) ); + CPPUNIT_ASSERT_EQUAL( 1, a.Index(1, /*bFromEnd=*/true) ); + CPPUNIT_ASSERT_EQUAL( 2, a.Index(42, /*bFromEnd=*/true) ); +}