diff options
Diffstat (limited to '')
-rw-r--r-- | src/old/tests/hash.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/old/tests/hash.cpp b/src/old/tests/hash.cpp new file mode 100644 index 0000000..2fc6968 --- /dev/null +++ b/src/old/tests/hash.cpp | |||
@@ -0,0 +1,116 @@ | |||
1 | #include "hash.h" | ||
2 | #include "staticstring.h" | ||
3 | |||
4 | int main() | ||
5 | { | ||
6 | const char *names[]={ | ||
7 | "Homer the Great", | ||
8 | "And Maggie Makes Three", | ||
9 | "Bart's Comet", | ||
10 | "Homie The Clown", | ||
11 | "Bart Vs Australia", | ||
12 | "Homer vs Patty and Selma", | ||
13 | "A star is burns", | ||
14 | "Lisa's Wedding", | ||
15 | "Two Dozen and One Greyhounds", | ||
16 | "The PTA Disbands", | ||
17 | "Round Springfield", | ||
18 | "The Springfield connection", | ||
19 | "Lemon of Troy", | ||
20 | "Who Shot Mr. Burns (Pt. 1)", | ||
21 | "Who Shot Mr. Burns (pt. 2)", | ||
22 | "Radioactive Man", | ||
23 | "Home Sweet Homediddly-dum-doodly", | ||
24 | "Bart Sells His Soul", | ||
25 | "Lisa the Vegetarian", | ||
26 | "Treehouse of horror VI", | ||
27 | "King Size Homer", | ||
28 | "Mother Simpson", | ||
29 | "Sideshow Bob's Last Gleaming", | ||
30 | "The Simpson's 138th Show Spectacular", | ||
31 | "Marge Be Not Proud", | ||
32 | "Team Homer", | ||
33 | "Two Bad Neighbors", | ||
34 | "Scenes From the Class Struggle in Springfield", | ||
35 | "Bart the Fink", | ||
36 | "Lisa the Iconoclast", | ||
37 | "Homer the Smithers", | ||
38 | "The Day the Violence Died", | ||
39 | "A Fish Called Selma", | ||
40 | "Bart on the road", | ||
41 | "22 Short Films about Springfield", | ||
42 | "The Curse of the Flying Hellfish", | ||
43 | "Much Apu about Nothing", | ||
44 | "Homerpalooza", | ||
45 | "The Summer of 4 Ft 2", | ||
46 | "Treehouse of Horror VII", | ||
47 | "You Only Move Twice", | ||
48 | "The Homer They Fall", | ||
49 | "Burns Baby Burns", | ||
50 | "Bart After Dark", | ||
51 | "A Millhouse Divided", | ||
52 | "Lisas Date With Destiny", | ||
53 | "Hurricane Neddy", | ||
54 | "The Mysterious Voyage of Our Homer", | ||
55 | "The Springfield Files", | ||
56 | "The Twisted World of Marge Simpson", | ||
57 | "Mountain of Madness", | ||
58 | NULL | ||
59 | }; | ||
60 | |||
61 | Hash<const char *, int> sTest; | ||
62 | |||
63 | printf("Inserting\n-------------------\n\n"); | ||
64 | for( int j = 0; j < 33; j++ ) | ||
65 | { | ||
66 | sTest[names[j]] = j; | ||
67 | } | ||
68 | |||
69 | printf("Test1: %d, Test2: %d\n", sTest.has("Lemon of Troy"), sTest.has(std::string("Lemon of Troy").c_str() ) ); | ||
70 | |||
71 | sTest.has(std::string("Lemon of Troy").c_str() ); | ||
72 | |||
73 | printf("Getting\n-------------------\n\n"); | ||
74 | |||
75 | sTest.erase("Homer the Great"); | ||
76 | sTest["Bart's Comet"].erase(); | ||
77 | |||
78 | for( Hash<const char *, int>::iterator i = sTest.begin(); | ||
79 | i != sTest.end(); i++ ) | ||
80 | { | ||
81 | Hash<const char *, int>::iterator j = i; | ||
82 | printf("%d: %s\n", (*j).second, (*j).first ); | ||
83 | } | ||
84 | |||
85 | printf("Testing\n-------------------\n\n"); | ||
86 | for( int j = 0; j < 33; j++ ) | ||
87 | { | ||
88 | if( sTest.has(names[j]) ) | ||
89 | { | ||
90 | if( sTest[names[j]] != j ) | ||
91 | { | ||
92 | printf("'%s' should be %d, is %d\n", | ||
93 | names[j], j, | ||
94 | sTest[names[j]].value() | ||
95 | ); | ||
96 | } | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | printf("Missing element %d, '%s'\n", j, names[j] ); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | printf("Clearing\n-------------------\n\n"); | ||
105 | |||
106 | sTest.clear(); | ||
107 | |||
108 | for( Hash<const char *, int>::iterator i = sTest.begin(); | ||
109 | i != sTest.end(); i++ ) | ||
110 | { | ||
111 | Hash<const char *, int>::iterator j = i; | ||
112 | printf("%d: %s\n", (*j).second, (*j).first ); | ||
113 | } | ||
114 | |||
115 | } | ||
116 | |||