3 * Code to test the KList ADT
4 * Test KList<Cstring> and KList<int>
6 * Present uses of functions
8 * Verified output is in klist_out
10 * The log for this test is in klist_out
16 * $Log: KListTest.C,v $
17 * Revision 1.1 1994/08/17 18:26:11 markc
18 * Code and sample output to test new classes.
24 #pragma implementation "klist.h"
25 #include "../h/klist.h"
27 #pragma implementation "cstring.h"
28 #include "../h/cstring.h"
30 #pragma implementation "keylist.h"
31 #include "../h/keylist.h"
33 int compare_cstring (const Cstring &a, const Cstring &b)
43 Cstring addTag(Cstring &item)
45 return(item + "happy");
48 void printTimesTwo (int &i)
50 cout << i << " * 2 = " << (2*i) << endl;
53 int printUntilZippy(const Cstring &i1, const Cstring &i2)
61 KList<int> iList, i2List;
62 KList<Cstring> cList, c2List, *pcList;
64 cout << " ilist empty = " << iList.empty() << endl;
65 cout << " clist empty = " << cList.empty() << endl;
67 cout << "Printing iList " << iList << endl;
68 cout << "Printing cList " << cList << endl;
75 cList.prepend("happy");
76 cList.append("zippy");
78 cout << "Printing iList " << iList << endl;
79 cout << "Printing cList " << cList << endl;
82 c2List.appendUnique("orange");
83 c2List.prependUnique("apple");
84 cout << "Printing c2List " << c2List << endl;
88 cout << "These lists should be equal\n";
89 cout << "Printing iList " << iList << endl;
90 cout << "Printing i2List " << iList << endl;
92 cout << "Printing c2List " << c2List << endl;
93 c2List.appendUnique("orange");
94 cout << "Printing c2List " << c2List << endl;
96 pcList = new KList<Cstring>(c2List);
98 cout << "Printing pcList " << *pcList << endl;
102 cout << "Printing c2List " << c2List << endl;
103 cout << "Printing cList " << cList << endl;
105 cout << "Printing iList (before 3) " << iList << endl;
107 cout << "Printing iList (removed 3) " << iList << endl;
109 cout << "Printing cList (before removing apple) " << cList << endl;
110 cList.remove("apple");
111 cout << "Printing cList (after removing apple) " << cList << endl;
114 cout << "Printing cList (before removing orange) " << cList << endl;
116 cList.find(a, fd1, 1, &compare_cstring);
117 cout << "Printing cList (after removing orange) " << cList << endl;
121 cout << "Printing iList " << iList << endl;
122 iList = iList.pure_map(&add1);
123 cout << "iList after pure_map(&add1) " << iList << endl;
125 cout << "iList after modify(&add1) " << iList << endl;
127 cout << "cList before modify(&addTag) " << cList << endl;
128 cList.modify(&addTag);
129 cout << "cList after modify(&addTag) " << cList << endl;
131 cout << " count of " << iList << " is " << iList.count()
132 << " the list is " << (iList.empty() ? " not " : " ")
133 << " empty " << endl;
134 cout << " count of " << cList << " is " << cList.count()
135 << " the list is " << (cList.empty() ? " not " : " ")
136 << " empty " << endl;
138 cout << " iList.map(&printTimesTwo) " << endl;
139 iList.map(&printTimesTwo);
141 cout << " cList.mapUntil(&printUntilZippy) " << endl;
142 cList.mapUntil("zippy", &printUntilZippy);
144 Cstring findem("sadhappy");
145 cout << " Search " << cList << " for " << findem << endl;
147 cout << "cList.find('sadhappy') = " << cList.find(findem, fd) << endl;
149 cout << "cdr (" << cList << " ) = " << cList.cdr() << endl;
150 cout << "cdr (" << iList << " ) = " << iList.cdr() << endl;
155 cout << " car ( " << cList << " ) = " << cList.car(valid) << endl;
159 cout << " car ( " << iList << " ) = " << iList.car(valid) << endl;
163 cout << " p1 = " << p1 << endl;
165 cout << " p1 = " << p1 << endl;
167 cout << " p1 = " << p1 << endl;
173 cout << "l1 = " << l1 << endl;
175 cout << "l1 = l1 --> " << l1 << endl;
177 cout << "l1 += l1 --> " << l1 << endl;
179 cout << "l1 reset " << l1 << endl;
181 cout << "l2 = " << l2 << endl;
182 cout << "l1 += l2 --> " << l1 << endl;
188 int i1=1, i2=2, i3=3, i4=4, i5=5, i6=6, i7=7, i8=8;
190 ilist.appendUnique(i1, (void*) i1);
191 ilist.appendUnique(i2, (void*) i2);
192 ilist.appendUnique(i3, (void*) i3);
193 ilist.appendUnique(i4, (void*) i4);
194 ilist.appendUnique(i5, (void*) i5);
195 ilist.appendUnique(i6, (void*) i6);
196 ilist.appendUnique(i7, (void*) i7);
197 ilist.appendUnique(i8, (void*) i8);
200 cout << "ilist = " << ilist << endl;
201 cout << " ilist.find(" << i1 << ") =" << ilist.find((void*) i1, v) << endl;
202 cout << " ilist.find(" << i2 << ") =" << ilist.find((void*) i2, v) << endl;
203 cout << " ilist.find(" << i3 << ") =" << ilist.find((void*) i3, v) << endl;
204 cout << " ilist.find(" << i4 << ") =" << ilist.find((void*) i4, v) << endl;
205 cout << " ilist.find(" << i5 << ") =" << ilist.find((void*) i5, v) << endl;
206 cout << " ilist.find(" << i6 << ") =" << ilist.find((void*) i6, v) << endl;
207 cout << " ilist.find(" << i7 << ") =" << ilist.find((void*) i7, v) << endl;
208 cout << " ilist.find(" << i8 << ") =" << ilist.find((void*) i8, v) << endl;
211 cout << "ilist.reverse() = " << ilist << endl;
215 KeyList<Cstring> slist;
216 slist.appendUnique("happy1", (void*) i1);
217 slist.appendUnique("happy2", (void*) i2);
218 slist.appendUnique("happy3", (void*) i3);
219 slist.appendUnique("happy4", (void*) i4);
220 cout << "slist = " << slist << endl;
221 cout << "slist.find(" << i1 << ") = " << slist.find((void*) i1, v) << endl;
223 cout << "slist.reverse() = " << slist << endl;
229 int j1=1, j2=2, j3=3, j4=4, j5=5, j6=6, j7=7, j8=8, j56=56;
232 i1.add(j1, (void*) j1);
233 i1.add(j2, (void*) j2);
234 i1.add(j3, (void*) j3);
235 i1.add(j4, (void*) j4);
236 i1.add(j5, (void*) j5);
237 i1.add(j6, (void*) j6);
238 i1.add(j7, (void*) j7);
239 i1.add(j8, (void*) j8);
240 i1.add(j56, (void*) j56);
242 cout << "table= " << i1 << endl;