X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a83f860948059b0273b5cc6d9e43fadad3ebfca..37d8aa5b686ec3b48aa9a6c480dd06738c5a9e64:/tests/arrays/arrays.cpp?ds=sidebyside diff --git a/tests/arrays/arrays.cpp b/tests/arrays/arrays.cpp index ed74c94835..ac48e92678 100644 --- a/tests/arrays/arrays.cpp +++ b/tests/arrays/arrays.cpp @@ -160,6 +160,7 @@ public: private: CPPUNIT_TEST_SUITE( ArraysTestCase ); CPPUNIT_TEST( wxStringArrayTest ); + CPPUNIT_TEST( SortedArray ); CPPUNIT_TEST( wxStringArraySplitTest ); CPPUNIT_TEST( wxStringArrayJoinTest ); CPPUNIT_TEST( wxStringArraySplitJoinTest ); @@ -172,9 +173,11 @@ private: CPPUNIT_TEST( Alloc ); CPPUNIT_TEST( Clear ); CPPUNIT_TEST( Swap ); + CPPUNIT_TEST( IndexFromEnd ); CPPUNIT_TEST_SUITE_END(); void wxStringArrayTest(); + void SortedArray(); void wxStringArraySplitTest(); void wxStringArrayJoinTest(); void wxStringArraySplitJoinTest(); @@ -186,6 +189,7 @@ private: void Alloc(); void Clear(); void Swap(); + void IndexFromEnd(); DECLARE_NO_COPY_CLASS(ArraysTestCase) }; @@ -193,7 +197,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() @@ -305,6 +309,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 ); @@ -327,6 +338,29 @@ void ArraysTestCase::wxStringArrayTest() CPPUNIT_ASSERT_EQUAL( WXSIZEOF(months), a5.size() ); CPPUNIT_ASSERT( COMPARE_3_VALUES(a5, "Jan", "Feb", "Mar") ); #endif // wxHAS_VECTOR_TEMPLATE_ASSIGN + + a5.clear(); + CPPUNIT_ASSERT_EQUAL( 0, a5.size() ); + + a5.resize(7, "Foo"); + CPPUNIT_ASSERT_EQUAL( 7, a5.size() ); + CPPUNIT_ASSERT_EQUAL( "Foo", a5[3] ); + + a5.resize(3); + CPPUNIT_ASSERT_EQUAL( 3, a5.size() ); + CPPUNIT_ASSERT_EQUAL( "Foo", a5[2] ); +} + +void ArraysTestCase::SortedArray() +{ + wxSortedArrayString a; + a.Add("d"); + a.Add("c"); + CPPUNIT_ASSERT_EQUAL( 0, a.Index("c") ); + + a.push_back("b"); + a.push_back("a"); + CPPUNIT_ASSERT_EQUAL( 0, a.Index("a") ); } void ArraysTestCase::wxStringArraySplitTest() @@ -681,3 +715,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) ); +}