summaryrefslogtreecommitdiff
path: root/test/containers.cc
blob: 40b2d8c8a9482cd5a20ff5b30e498fd00505571f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "../lout/object.hh"
#include "../lout/container.hh"

using namespace lout::object;
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"));
   
   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));
   
   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 testVector1 ()
{
   puts ("--- testVector (1) ---");

   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());
}

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());

   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");
   
      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));
      }
   }
}

int main (int argc, char *argv[])
{
   testHashSet ();
   testHashTable ();
   testVector1 ();
   testVector2 ();

   return 0;
}