]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0011-hashmap.sh
Merge branch 'dl/reset-doc-no-wrt-abbrev'
[thirdparty/git.git] / t / t0011-hashmap.sh
CommitLineData
6a364ced
KB
1#!/bin/sh
2
3test_description='test hashmap and string hash functions'
4. ./test-lib.sh
5
6test_hashmap() {
7c18cbd5 7 echo "$1" | test-tool hashmap $3 > actual &&
6a364ced
KB
8 echo "$2" > expect &&
9 test_cmp expect actual
10}
11
12test_expect_success 'hash functions' '
13
14test_hashmap "hash key1" "2215982743 2215982743 116372151 116372151" &&
15test_hashmap "hash key2" "2215982740 2215982740 116372148 116372148" &&
16test_hashmap "hash fooBarFrotz" "1383912807 1383912807 3189766727 3189766727" &&
17test_hashmap "hash foobarfrotz" "2862305959 2862305959 3189766727 3189766727"
18
19'
20
21test_expect_success 'put' '
22
23test_hashmap "put key1 value1
24put key2 value2
25put fooBarFrotz value3
26put foobarfrotz value4
27size" "NULL
28NULL
29NULL
30NULL
3164 4"
32
33'
34
35test_expect_success 'put (case insensitive)' '
36
37test_hashmap "put key1 value1
38put key2 value2
39put fooBarFrotz value3
40size" "NULL
41NULL
42NULL
4364 3" ignorecase
44
45'
46
47test_expect_success 'replace' '
48
49test_hashmap "put key1 value1
50put key1 value2
51put fooBarFrotz value3
52put fooBarFrotz value4
53size" "NULL
54value1
55NULL
56value3
5764 2"
58
59'
60
61test_expect_success 'replace (case insensitive)' '
62
63test_hashmap "put key1 value1
64put Key1 value2
65put fooBarFrotz value3
66put foobarfrotz value4
67size" "NULL
68value1
69NULL
70value3
7164 2" ignorecase
72
73'
74
75test_expect_success 'get' '
76
77test_hashmap "put key1 value1
78put key2 value2
79put fooBarFrotz value3
80put foobarfrotz value4
81get key1
82get key2
83get fooBarFrotz
84get notInMap" "NULL
85NULL
86NULL
87NULL
88value1
89value2
90value3
91NULL"
92
93'
94
95test_expect_success 'get (case insensitive)' '
96
97test_hashmap "put key1 value1
98put key2 value2
99put fooBarFrotz value3
100get Key1
101get keY2
102get foobarfrotz
103get notInMap" "NULL
104NULL
105NULL
106value1
107value2
108value3
109NULL" ignorecase
110
111'
112
113test_expect_success 'add' '
114
115test_hashmap "add key1 value1
116add key1 value2
117add fooBarFrotz value3
118add fooBarFrotz value4
119get key1
120get fooBarFrotz
121get notInMap" "value2
122value1
123value4
124value3
125NULL"
126
127'
128
129test_expect_success 'add (case insensitive)' '
130
131test_hashmap "add key1 value1
132add Key1 value2
133add fooBarFrotz value3
134add foobarfrotz value4
135get key1
136get Foobarfrotz
137get notInMap" "value2
138value1
139value4
140value3
141NULL" ignorecase
142
143'
144
145test_expect_success 'remove' '
146
147test_hashmap "put key1 value1
148put key2 value2
149put fooBarFrotz value3
150remove key1
151remove key2
152remove notInMap
153size" "NULL
154NULL
155NULL
156value1
157value2
158NULL
15964 1"
160
161'
162
163test_expect_success 'remove (case insensitive)' '
164
165test_hashmap "put key1 value1
166put key2 value2
167put fooBarFrotz value3
168remove Key1
169remove keY2
170remove notInMap
171size" "NULL
172NULL
173NULL
174value1
175value2
176NULL
17764 1" ignorecase
178
179'
180
181test_expect_success 'iterate' '
182
183test_hashmap "put key1 value1
184put key2 value2
185put fooBarFrotz value3
186iterate" "NULL
187NULL
188NULL
189key2 value2
190key1 value1
191fooBarFrotz value3"
192
193'
194
195test_expect_success 'iterate (case insensitive)' '
196
197test_hashmap "put key1 value1
198put key2 value2
199put fooBarFrotz value3
200iterate" "NULL
201NULL
202NULL
203fooBarFrotz value3
204key2 value2
205key1 value1" ignorecase
206
207'
208
209test_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 &&
7c18cbd5 235 cat in | test-tool hashmap > out &&
6a364ced
KB
236 test_cmp expect out
237
238'
239
7b64d42d
KB
240test_expect_success 'string interning' '
241
242test_hashmap "intern value1
243intern Value1
244intern value2
245intern value2
246" "value1
247Value1
248value2
249value2"
250
251'
252
6a364ced 253test_done