diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2013-03-06 23:16:28 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2013-03-06 23:16:28 +0100 |
commit | eb1ace98ed5f372ecfaa3c04ea63731856d6ac75 (patch) | |
tree | f46f938802ffeeef1ecdc09108c691b6fd42d21f | |
parent | bf8c14fb9204f7ba625819e6a056a00c108bb945 (diff) | |
parent | 58cafbd3e2e8871b93cc3717d771cf068c10a304 (diff) |
merge
-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; } |