aboutsummaryrefslogtreecommitdiff
path: root/test/containers.cc
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2013-03-05 14:28:34 +0100
committerSebastian Geerken <devnull@localhost>2013-03-05 14:28:34 +0100
commit09cbe1a36c6ca2762d2e49f173db7ee4fb683448 (patch)
treeaaf322ad1388f2c8a507d1c6a51779c8dd025f24 /test/containers.cc
parent98465834b8b0e7c4a563e651a51befd2a2ab06ac (diff)
parente844f4119a6a5b144b18af4bcc841c816f575159 (diff)
Merge with main repo.
Diffstat (limited to 'test/containers.cc')
-rw-r--r--test/containers.cc64
1 files changed, 50 insertions, 14 deletions
diff --git a/test/containers.cc b/test/containers.cc
index 646624aa..d8107bdf 100644
--- a/test/containers.cc
+++ b/test/containers.cc
@@ -6,41 +6,76 @@ using namespace lout::container::typed;
void testHashSet ()
{
+ puts ("--- testHashSet ---");
+
HashSet<String> h(true);
h.put (new String ("one"));
h.put (new String ("two"));
h.put (new String ("three"));
- Iterator<String> it = h.iterator ();
- while (it.hasNext ()) {
- String *o = it.getNext ();
- printf ("%s\n", o->chars());
- }
+ puts (h.toString());
}
void testHashTable ()
{
+ puts ("--- testHashTable ---");
+
HashTable<String, Integer> h(true, true);
h.put (new String ("one"), new Integer (1));
h.put (new String ("two"), new Integer (2));
h.put (new String ("three"), new Integer (3));
- for (Iterator<String> it = h.iterator (); it.hasNext (); ) {
- String *k = it.getNext ();
- Integer *v = h.get (k);
- printf ("%s -> %d\n", k->chars(), v->getValue());
- }
+ puts (h.toString());
h.put (new String ("one"), new Integer (4));
h.put (new String ("two"), new Integer (5));
h.put (new String ("three"), new Integer (6));
+
+ puts (h.toString());
+}
+
+void testVector ()
+{
+ puts ("--- testVector ---");
+
+ Vector<String> v (true, 1);
+
+ v.put (new String ("one"));
+ v.put (new String ("two"));
+ v.put (new String ("three"));
+ puts (v.toString());
+
+ v.sort ();
+ puts (v.toString());
+
+ v.insertSorted (new String ("five"));
+ puts (v.toString());
+
+ v.insertSorted (new String ("six"));
+ puts (v.toString());
+
+ v.insertSorted (new String ("four"));
+ puts (v.toString());
+
+ for (int b = 0; b < 2; b++) {
+ bool mustExist = b;
+ printf ("mustExist = %s\n", mustExist ? "true" : "false");
- for (Iterator<String> it = h.iterator (); it.hasNext (); ) {
- String *k = it.getNext ();
- Integer *v = h.get (k);
- printf ("%s -> %d\n", k->chars(), v->getValue());
+ String k ("alpha");
+ printf (" '%s' -> %d\n", k.chars(), v.bsearch (&k, mustExist));
+
+ for (Iterator<String> it = v.iterator(); it.hasNext(); ) {
+ String *k1 = it.getNext();
+ printf (" '%s' -> %d\n", k1->chars(), v.bsearch (k1, mustExist));
+
+ char buf[64];
+ strcpy (buf, k1->chars());
+ strcat (buf, "-var");
+ String k2 (buf);
+ printf (" '%s' -> %d\n", k2.chars(), v.bsearch (&k2, mustExist));
+ }
}
}
@@ -48,6 +83,7 @@ int main (int argc, char *argv[])
{
testHashSet ();
testHashTable ();
+ testVector ();
return 0;
}