]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix wxSortedArray::Index() when wxUSE_STL == 1, with tests.
authorMattia Barbon <mbarbon@cpan.org>
Sat, 22 Jan 2005 13:28:49 +0000 (13:28 +0000)
committerMattia Barbon <mbarbon@cpan.org>
Sat, 22 Jan 2005 13:28:49 +0000 (13:28 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31559 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/dynarray.cpp
tests/arrays/arrays.cpp

index 738e9813a39a140945104945b8d424fd221c7872..4f4915a25bb18965353d51ffac2f19974bb28b76 100644 (file)
@@ -99,8 +99,8 @@ int name::Index(T lItem, CMPFUNC fnCompare) const                           \
 {                                                                           \
     Predicate p((SCMPFUNC)fnCompare);                                       \
     const_iterator it = std::lower_bound(begin(), end(), lItem, p);         \
-    return (it != end() &&                                                  \
-            p(lItem, *it)) ? (int)(it - begin()) : wxNOT_FOUND;             \
+    return (it != end() && !p(lItem, *it)) ?                                \
+                             (int)(it - begin()) : wxNOT_FOUND;             \
 }                                                                           \
                                                                             \
 void name::Shrink()                                                         \
index 719b266f303ab0b173f2b6aca59a7d7c30e5d724..c27f6a4a2d5560398b4eade9e07d50ffaa5ce28b 100644 (file)
@@ -268,6 +268,12 @@ void ArraysTestCase::wxStringArrayTest()
                                            _T("thermit") ,
                                            _T("alligator") ) );
     CPPUNIT_ASSERT( COMPARE_COUNT( a1 , 5 ) );
+    CPPUNIT_ASSERT( a1.Index( "dog" ) == 0 );
+    CPPUNIT_ASSERT( a1.Index( "human" ) == 1 );
+    CPPUNIT_ASSERT( a1.Index( "humann" ) == wxNOT_FOUND );
+    CPPUNIT_ASSERT( a1.Index( "condor" ) == 2 );
+    CPPUNIT_ASSERT( a1.Index( "thermit" ) == 3 );
+    CPPUNIT_ASSERT( a1.Index( "alligator" ) == 4 );
 }
 
 void ArraysTestCase::wxObjArrayTest()
@@ -330,6 +336,13 @@ void ArraysTestCase::wxArray ## name ## Test()                                \
                                                                               \
     CPPUNIT_ASSERT( COMPARE_4_VALUES(b,1,3,5,17) );                           \
     CPPUNIT_ASSERT( COMPARE_COUNT( b , 4 ) );                                 \
+    CPPUNIT_ASSERT( b.Index( 0 ) == wxNOT_FOUND );                            \
+    CPPUNIT_ASSERT( b.Index( 1 ) == 0 );                                      \
+    CPPUNIT_ASSERT( b.Index( 3 ) == 1 );                                      \
+    CPPUNIT_ASSERT( b.Index( 4 ) == wxNOT_FOUND );                            \
+    CPPUNIT_ASSERT( b.Index( 5 ) == 2 );                                      \
+    CPPUNIT_ASSERT( b.Index( 6 ) == wxNOT_FOUND );                            \
+    CPPUNIT_ASSERT( b.Index( 17 ) == 3 );                                     \
 }
 
 TestArrayOf(UShort);