diff options
-rw-r--r-- | lout/container.cc | 2 | ||||
-rw-r--r-- | test/containers.cc | 23 |
2 files changed, 22 insertions, 3 deletions
diff --git a/lout/container.cc b/lout/container.cc index 5e5eda73..de36a6f7 100644 --- a/lout/container.cc +++ b/lout/container.cc @@ -206,6 +206,8 @@ int Vector::bsearch(Object *key, bool mustExist) { // The case !mustExist is not handled by bsearch(3), so here is a // new implementation. + if (numElements == 0) + return mustExist ? -1 : 0; int high = numElements - 1, low = 0; diff --git a/test/containers.cc b/test/containers.cc index d8107bdf..40b2d8c8 100644 --- a/test/containers.cc +++ b/test/containers.cc @@ -36,9 +36,9 @@ void testHashTable () puts (h.toString()); } -void testVector () +void testVector1 () { - puts ("--- testVector ---"); + puts ("--- testVector (1) ---"); Vector<String> v (true, 1); @@ -49,7 +49,23 @@ void testVector () v.sort (); puts (v.toString()); +} + +void testVector2 () +{ + puts ("--- testVector (2) ---"); + Vector<String> v (true, 1); + + v.insertSorted (new String ("one")); + puts (v.toString()); + + v.insertSorted (new String ("two")); + puts (v.toString()); + + v.insertSorted (new String ("three")); + puts (v.toString()); + v.insertSorted (new String ("five")); puts (v.toString()); @@ -83,7 +99,8 @@ int main (int argc, char *argv[]) { testHashSet (); testHashTable (); - testVector (); + testVector1 (); + testVector2 (); return 0; } |