]>
Commit | Line | Data |
---|---|---|
6a364ced KB |
1 | #!/bin/sh |
2 | ||
3 | test_description='test hashmap and string hash functions' | |
4 | . ./test-lib.sh | |
5 | ||
6 | test_hashmap() { | |
7 | echo "$1" | test-hashmap $3 > actual && | |
8 | echo "$2" > expect && | |
9 | test_cmp expect actual | |
10 | } | |
11 | ||
12 | test_expect_success 'hash functions' ' | |
13 | ||
14 | test_hashmap "hash key1" "2215982743 2215982743 116372151 116372151" && | |
15 | test_hashmap "hash key2" "2215982740 2215982740 116372148 116372148" && | |
16 | test_hashmap "hash fooBarFrotz" "1383912807 1383912807 3189766727 3189766727" && | |
17 | test_hashmap "hash foobarfrotz" "2862305959 2862305959 3189766727 3189766727" | |
18 | ||
19 | ' | |
20 | ||
21 | test_expect_success 'put' ' | |
22 | ||
23 | test_hashmap "put key1 value1 | |
24 | put key2 value2 | |
25 | put fooBarFrotz value3 | |
26 | put foobarfrotz value4 | |
27 | size" "NULL | |
28 | NULL | |
29 | NULL | |
30 | NULL | |
31 | 64 4" | |
32 | ||
33 | ' | |
34 | ||
35 | test_expect_success 'put (case insensitive)' ' | |
36 | ||
37 | test_hashmap "put key1 value1 | |
38 | put key2 value2 | |
39 | put fooBarFrotz value3 | |
40 | size" "NULL | |
41 | NULL | |
42 | NULL | |
43 | 64 3" ignorecase | |
44 | ||
45 | ' | |
46 | ||
47 | test_expect_success 'replace' ' | |
48 | ||
49 | test_hashmap "put key1 value1 | |
50 | put key1 value2 | |
51 | put fooBarFrotz value3 | |
52 | put fooBarFrotz value4 | |
53 | size" "NULL | |
54 | value1 | |
55 | NULL | |
56 | value3 | |
57 | 64 2" | |
58 | ||
59 | ' | |
60 | ||
61 | test_expect_success 'replace (case insensitive)' ' | |
62 | ||
63 | test_hashmap "put key1 value1 | |
64 | put Key1 value2 | |
65 | put fooBarFrotz value3 | |
66 | put foobarfrotz value4 | |
67 | size" "NULL | |
68 | value1 | |
69 | NULL | |
70 | value3 | |
71 | 64 2" ignorecase | |
72 | ||
73 | ' | |
74 | ||
75 | test_expect_success 'get' ' | |
76 | ||
77 | test_hashmap "put key1 value1 | |
78 | put key2 value2 | |
79 | put fooBarFrotz value3 | |
80 | put foobarfrotz value4 | |
81 | get key1 | |
82 | get key2 | |
83 | get fooBarFrotz | |
84 | get notInMap" "NULL | |
85 | NULL | |
86 | NULL | |
87 | NULL | |
88 | value1 | |
89 | value2 | |
90 | value3 | |
91 | NULL" | |
92 | ||
93 | ' | |
94 | ||
95 | test_expect_success 'get (case insensitive)' ' | |
96 | ||
97 | test_hashmap "put key1 value1 | |
98 | put key2 value2 | |
99 | put fooBarFrotz value3 | |
100 | get Key1 | |
101 | get keY2 | |
102 | get foobarfrotz | |
103 | get notInMap" "NULL | |
104 | NULL | |
105 | NULL | |
106 | value1 | |
107 | value2 | |
108 | value3 | |
109 | NULL" ignorecase | |
110 | ||
111 | ' | |
112 | ||
113 | test_expect_success 'add' ' | |
114 | ||
115 | test_hashmap "add key1 value1 | |
116 | add key1 value2 | |
117 | add fooBarFrotz value3 | |
118 | add fooBarFrotz value4 | |
119 | get key1 | |
120 | get fooBarFrotz | |
121 | get notInMap" "value2 | |
122 | value1 | |
123 | value4 | |
124 | value3 | |
125 | NULL" | |
126 | ||
127 | ' | |
128 | ||
129 | test_expect_success 'add (case insensitive)' ' | |
130 | ||
131 | test_hashmap "add key1 value1 | |
132 | add Key1 value2 | |
133 | add fooBarFrotz value3 | |
134 | add foobarfrotz value4 | |
135 | get key1 | |
136 | get Foobarfrotz | |
137 | get notInMap" "value2 | |
138 | value1 | |
139 | value4 | |
140 | value3 | |
141 | NULL" ignorecase | |
142 | ||
143 | ' | |
144 | ||
145 | test_expect_success 'remove' ' | |
146 | ||
147 | test_hashmap "put key1 value1 | |
148 | put key2 value2 | |
149 | put fooBarFrotz value3 | |
150 | remove key1 | |
151 | remove key2 | |
152 | remove notInMap | |
153 | size" "NULL | |
154 | NULL | |
155 | NULL | |
156 | value1 | |
157 | value2 | |
158 | NULL | |
159 | 64 1" | |
160 | ||
161 | ' | |
162 | ||
163 | test_expect_success 'remove (case insensitive)' ' | |
164 | ||
165 | test_hashmap "put key1 value1 | |
166 | put key2 value2 | |
167 | put fooBarFrotz value3 | |
168 | remove Key1 | |
169 | remove keY2 | |
170 | remove notInMap | |
171 | size" "NULL | |
172 | NULL | |
173 | NULL | |
174 | value1 | |
175 | value2 | |
176 | NULL | |
177 | 64 1" ignorecase | |
178 | ||
179 | ' | |
180 | ||
181 | test_expect_success 'iterate' ' | |
182 | ||
183 | test_hashmap "put key1 value1 | |
184 | put key2 value2 | |
185 | put fooBarFrotz value3 | |
186 | iterate" "NULL | |
187 | NULL | |
188 | NULL | |
189 | key2 value2 | |
190 | key1 value1 | |
191 | fooBarFrotz value3" | |
192 | ||
193 | ' | |
194 | ||
195 | test_expect_success 'iterate (case insensitive)' ' | |
196 | ||
197 | test_hashmap "put key1 value1 | |
198 | put key2 value2 | |
199 | put fooBarFrotz value3 | |
200 | iterate" "NULL | |
201 | NULL | |
202 | NULL | |
203 | fooBarFrotz value3 | |
204 | key2 value2 | |
205 | key1 value1" ignorecase | |
206 | ||
207 | ' | |
208 | ||
209 | test_expect_success 'grow / shrink' ' | |
210 | ||
211 | rm -f in && | |
212 | rm -f expect && | |
213 | for n in $(test_seq 51) | |
214 | do | |
215 | echo put key$n value$n >> in && | |
216 | echo NULL >> expect | |
217 | done && | |
218 | echo size >> in && | |
219 | echo 64 51 >> expect && | |
220 | echo put key52 value52 >> in && | |
99094a7a | 221 | echo NULL >> expect && |
6a364ced KB |
222 | echo size >> in && |
223 | echo 256 52 >> expect && | |
224 | for n in $(test_seq 12) | |
225 | do | |
226 | echo remove key$n >> in && | |
227 | echo value$n >> expect | |
228 | done && | |
229 | echo size >> in && | |
230 | echo 256 40 >> expect && | |
231 | echo remove key40 >> in && | |
232 | echo value40 >> expect && | |
233 | echo size >> in && | |
234 | echo 64 39 >> expect && | |
235 | cat in | test-hashmap > out && | |
236 | test_cmp expect out | |
237 | ||
238 | ' | |
239 | ||
7b64d42d KB |
240 | test_expect_success 'string interning' ' |
241 | ||
242 | test_hashmap "intern value1 | |
243 | intern Value1 | |
244 | intern value2 | |
245 | intern value2 | |
246 | " "value1 | |
247 | Value1 | |
248 | value2 | |
249 | value2" | |
250 | ||
251 | ' | |
252 | ||
6a364ced | 253 | test_done |