THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

245 lines
3.2KB

  1. #!/bin/sh
  2. test_description='test hashmap and string hash functions'
  3. . ./test-lib.sh
  4. test_hashmap() {
  5. echo "$1" | test-tool hashmap $3 > actual &&
  6. echo "$2" > expect &&
  7. test_cmp expect actual
  8. }
  9. test_expect_success 'put' '
  10. test_hashmap "put key1 value1
  11. put key2 value2
  12. put fooBarFrotz value3
  13. put foobarfrotz value4
  14. size" "NULL
  15. NULL
  16. NULL
  17. NULL
  18. 64 4"
  19. '
  20. test_expect_success 'put (case insensitive)' '
  21. test_hashmap "put key1 value1
  22. put key2 value2
  23. put fooBarFrotz value3
  24. size" "NULL
  25. NULL
  26. NULL
  27. 64 3" ignorecase
  28. '
  29. test_expect_success 'replace' '
  30. test_hashmap "put key1 value1
  31. put key1 value2
  32. put fooBarFrotz value3
  33. put fooBarFrotz value4
  34. size" "NULL
  35. value1
  36. NULL
  37. value3
  38. 64 2"
  39. '
  40. test_expect_success 'replace (case insensitive)' '
  41. test_hashmap "put key1 value1
  42. put Key1 value2
  43. put fooBarFrotz value3
  44. put foobarfrotz value4
  45. size" "NULL
  46. value1
  47. NULL
  48. value3
  49. 64 2" ignorecase
  50. '
  51. test_expect_success 'get' '
  52. test_hashmap "put key1 value1
  53. put key2 value2
  54. put fooBarFrotz value3
  55. put foobarfrotz value4
  56. get key1
  57. get key2
  58. get fooBarFrotz
  59. get notInMap" "NULL
  60. NULL
  61. NULL
  62. NULL
  63. value1
  64. value2
  65. value3
  66. NULL"
  67. '
  68. test_expect_success 'get (case insensitive)' '
  69. test_hashmap "put key1 value1
  70. put key2 value2
  71. put fooBarFrotz value3
  72. get Key1
  73. get keY2
  74. get foobarfrotz
  75. get notInMap" "NULL
  76. NULL
  77. NULL
  78. value1
  79. value2
  80. value3
  81. NULL" ignorecase
  82. '
  83. test_expect_success 'add' '
  84. test_hashmap "add key1 value1
  85. add key1 value2
  86. add fooBarFrotz value3
  87. add fooBarFrotz value4
  88. get key1
  89. get fooBarFrotz
  90. get notInMap" "value2
  91. value1
  92. value4
  93. value3
  94. NULL"
  95. '
  96. test_expect_success 'add (case insensitive)' '
  97. test_hashmap "add key1 value1
  98. add Key1 value2
  99. add fooBarFrotz value3
  100. add foobarfrotz value4
  101. get key1
  102. get Foobarfrotz
  103. get notInMap" "value2
  104. value1
  105. value4
  106. value3
  107. NULL" ignorecase
  108. '
  109. test_expect_success 'remove' '
  110. test_hashmap "put key1 value1
  111. put key2 value2
  112. put fooBarFrotz value3
  113. remove key1
  114. remove key2
  115. remove notInMap
  116. size" "NULL
  117. NULL
  118. NULL
  119. value1
  120. value2
  121. NULL
  122. 64 1"
  123. '
  124. test_expect_success 'remove (case insensitive)' '
  125. test_hashmap "put key1 value1
  126. put key2 value2
  127. put fooBarFrotz value3
  128. remove Key1
  129. remove keY2
  130. remove notInMap
  131. size" "NULL
  132. NULL
  133. NULL
  134. value1
  135. value2
  136. NULL
  137. 64 1" ignorecase
  138. '
  139. test_expect_success 'iterate' '
  140. test_hashmap "put key1 value1
  141. put key2 value2
  142. put fooBarFrotz value3
  143. iterate" "NULL
  144. NULL
  145. NULL
  146. key2 value2
  147. key1 value1
  148. fooBarFrotz value3"
  149. '
  150. test_expect_success 'iterate (case insensitive)' '
  151. test_hashmap "put key1 value1
  152. put key2 value2
  153. put fooBarFrotz value3
  154. iterate" "NULL
  155. NULL
  156. NULL
  157. fooBarFrotz value3
  158. key2 value2
  159. key1 value1" ignorecase
  160. '
  161. test_expect_success 'grow / shrink' '
  162. rm -f in &&
  163. rm -f expect &&
  164. for n in $(test_seq 51)
  165. do
  166. echo put key$n value$n >> in &&
  167. echo NULL >> expect
  168. done &&
  169. echo size >> in &&
  170. echo 64 51 >> expect &&
  171. echo put key52 value52 >> in &&
  172. echo NULL >> expect &&
  173. echo size >> in &&
  174. echo 256 52 >> expect &&
  175. for n in $(test_seq 12)
  176. do
  177. echo remove key$n >> in &&
  178. echo value$n >> expect
  179. done &&
  180. echo size >> in &&
  181. echo 256 40 >> expect &&
  182. echo remove key40 >> in &&
  183. echo value40 >> expect &&
  184. echo size >> in &&
  185. echo 64 39 >> expect &&
  186. cat in | test-tool hashmap > out &&
  187. test_cmp expect out
  188. '
  189. test_expect_success 'string interning' '
  190. test_hashmap "intern value1
  191. intern Value1
  192. intern value2
  193. intern value2
  194. " "value1
  195. Value1
  196. value2
  197. value2"
  198. '
  199. test_done