/test/lib/storage/dictionary/bijective_dictionary_tester.e

http://github.com/tybor/Liberty · Specman e · 247 lines · 196 code · 28 blank · 23 comment · 2 complexity · 8231fe3ba02bccdb9981e504ba748d8c MD5 · raw file

  1. -- This file is part of SmartEiffel The GNU Eiffel Compiler Tools and Libraries.
  2. -- See the Copyright notice at the end of this file.
  3. --
  4. class BIJECTIVE_DICTIONARY_TESTER[V_, K_]
  5. inherit
  6. BIJECTIVE_DICTIONARY[V_, K_]
  7. insert
  8. EIFFELTEST_TOOLS
  9. undefine is_equal
  10. end
  11. create {ANY}
  12. test
  13. feature {ANY}
  14. reference_at (k: K_): V_
  15. do
  16. Result := tested.reference_at(k)
  17. assert(Result = ref.reference_at(k))
  18. end
  19. fast_reference_at (k: K_): V_
  20. do
  21. Result := tested.fast_reference_at(k)
  22. assert(Result = ref.fast_reference_at(k))
  23. end
  24. internal_key (k: K_): K_
  25. do
  26. Result := tested.internal_key(k)
  27. assert(Result = ref.internal_key(k))
  28. end
  29. add (v: V_; k: K_)
  30. do
  31. tested.add(v, k)
  32. ref.add(v, k)
  33. same_dictionaries
  34. end
  35. fast_has (k: K_): BOOLEAN
  36. do
  37. Result := tested.fast_has(k)
  38. assert(Result = ref.fast_has(k))
  39. end
  40. has (k: K_): BOOLEAN
  41. do
  42. Result := tested.has(k)
  43. assert(Result = ref.has(k))
  44. end
  45. remove (k: K_)
  46. do
  47. tested.remove(k)
  48. ref.remove(k)
  49. same_dictionaries
  50. end
  51. clear_count
  52. do
  53. tested.clear_count
  54. ref.clear_count
  55. same_dictionaries
  56. end
  57. clear_count_and_capacity
  58. do
  59. tested.clear_count_and_capacity
  60. ref.clear_count_and_capacity
  61. same_dictionaries
  62. end
  63. fast_has_value (v: V_): BOOLEAN
  64. local
  65. i: INTEGER
  66. do
  67. Result := tested.has_value(v)
  68. from
  69. i := ref.lower
  70. until
  71. i > ref.upper or else v = ref.item(i)
  72. loop
  73. i := i + 1
  74. end
  75. assert(Result = (i <= ref.upper))
  76. end
  77. capacity: INTEGER
  78. do
  79. Result := tested.capacity.min(ref.capacity)
  80. end
  81. key_at (v: V_): K_
  82. local
  83. i: INTEGER
  84. do
  85. Result := tested.key_at(v)
  86. from
  87. i := ref.lower
  88. until
  89. val_safe_equal(v, ref.item(i))
  90. loop
  91. i := i + 1
  92. end
  93. assert(Result = ref.key(i))
  94. end
  95. fast_at (k: K_): V_
  96. do
  97. Result := tested.fast_at(k)
  98. assert(Result = ref.fast_at(k))
  99. end
  100. item (i: INTEGER): V_
  101. do
  102. Result := tested.item(i)
  103. -- No assertion here
  104. end
  105. fast_key_at (v: V_): K_
  106. local
  107. i: INTEGER
  108. do
  109. Result := tested.fast_key_at(v)
  110. from
  111. i := ref.lower
  112. until
  113. v = ref.item(i)
  114. loop
  115. i := i + 1
  116. end
  117. assert(Result = ref.key(i))
  118. end
  119. put (v: V_; k: K_)
  120. do
  121. tested.put(v, k)
  122. ref.put(v, k)
  123. same_dictionaries
  124. end
  125. at (k: K_): V_
  126. do
  127. Result := tested.at(k)
  128. assert(Result = ref.at(k))
  129. end
  130. key (i: INTEGER): K_
  131. do
  132. Result := tested.key(i)
  133. -- No assertion here
  134. end
  135. count: INTEGER
  136. do
  137. Result := tested.count
  138. assert(Result = ref.count)
  139. same_dictionaries
  140. end
  141. has_value (v: V_): BOOLEAN
  142. local
  143. i: INTEGER
  144. do
  145. Result := tested.has_value(v)
  146. from
  147. i := ref.lower
  148. until
  149. i > ref.upper or else val_safe_equal(v, ref.item(i))
  150. loop
  151. i := i + 1
  152. end
  153. assert(Result = (i <= ref.upper))
  154. end
  155. feature {}
  156. test (tested_: like tested)
  157. local
  158. i: INTEGER
  159. do
  160. tested := tested_
  161. create ref.with_capacity(tested.capacity)
  162. from
  163. i := tested.lower
  164. until
  165. i > tested.upper
  166. loop
  167. ref.put(tested.item(i), tested.key(i))
  168. i := i + 1
  169. end
  170. end
  171. same_dictionaries
  172. local
  173. i: INTEGER; v: V_; k: K_
  174. do
  175. assert(ref.count = tested.count)
  176. from
  177. i := ref.lower
  178. until
  179. i > ref.upper
  180. loop
  181. v := ref.item(i)
  182. k := ref.key(i)
  183. assert(tested.fast_has(k))
  184. assert(tested.fast_at(k) = v)
  185. i := i + 1
  186. end
  187. from
  188. i := tested.lower
  189. until
  190. i > tested.upper
  191. loop
  192. v := tested.item(i)
  193. k := tested.key(i)
  194. assert(ref.fast_has(k))
  195. assert(ref.fast_at(k) = v)
  196. i := i + 1
  197. end
  198. end
  199. ref: ARRAY_DICTIONARY[V_, K_]
  200. tested: BIJECTIVE_DICTIONARY[V_, K_]
  201. end -- class BIJECTIVE_DICTIONARY_TESTER
  202. --
  203. -- ------------------------------------------------------------------------------------------------------------------------------
  204. -- Copyright notice below. Please read.
  205. --
  206. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  207. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  208. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  209. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  210. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  211. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  212. --
  213. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  214. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  215. --
  216. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  217. --
  218. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  219. -- ------------------------------------------------------------------------------------------------------------------------------