/test/lib/storage/dictionary/test_avl.e

http://github.com/tybor/Liberty · Specman e · 117 lines · 87 code · 9 blank · 21 comment · 0 complexity · 66e2239d09450f5aa5c24a2a9a2b3c56 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 TEST_AVL
  5. inherit
  6. EIFFELTEST_TOOLS
  7. create {}
  8. make
  9. feature {}
  10. make
  11. do
  12. test_dictionary
  13. test_set
  14. end
  15. test_dictionary
  16. local
  17. dico: AVL_DICTIONARY[STRING, STRING]
  18. iter: ITERATOR[STRING]
  19. do
  20. create dico.make
  21. dico.add("W", "B")
  22. dico.add("X", "A")
  23. dico.add("Z", "@")
  24. dico.add("Y", "C")
  25. assert(dico.at("B").same_as("W"))
  26. assert(dico.at("A").same_as("X"))
  27. assert(dico.at("C").same_as("Y"))
  28. assert(dico.at("@").same_as("Z"))
  29. iter := dico.new_iterator_on_keys
  30. iter.start
  31. assert(not iter.is_off)
  32. assert(iter.item.same_as("@"))
  33. iter.next
  34. assert(not iter.is_off)
  35. assert(iter.item.same_as("A"))
  36. iter.next
  37. assert(not iter.is_off)
  38. assert(iter.item.same_as("B"))
  39. iter.next
  40. assert(not iter.is_off)
  41. assert(iter.item.same_as("C"))
  42. iter.next
  43. assert(iter.is_off)
  44. iter := dico.new_iterator_on_items
  45. iter.start
  46. assert(not iter.is_off)
  47. assert(iter.item.same_as("Z"))
  48. iter.next
  49. assert(not iter.is_off)
  50. assert(iter.item.same_as("X"))
  51. iter.next
  52. assert(not iter.is_off)
  53. assert(iter.item.same_as("W"))
  54. iter.next
  55. assert(not iter.is_off)
  56. assert(iter.item.same_as("Y"))
  57. iter.next
  58. assert(iter.is_off)
  59. end
  60. test_set
  61. local
  62. set: AVL_SET[STRING]
  63. iter: ITERATOR[STRING]
  64. do
  65. create set.make
  66. set.add("B")
  67. set.add("A")
  68. set.add("@")
  69. set.add("C")
  70. assert(set.has("@"))
  71. assert(set.has("A"))
  72. assert(set.has("B"))
  73. assert(set.has("C"))
  74. iter := set.new_iterator
  75. iter.start
  76. assert(not iter.is_off)
  77. assert(iter.item.same_as("@"))
  78. iter.next
  79. assert(not iter.is_off)
  80. assert(iter.item.same_as("A"))
  81. iter.next
  82. assert(not iter.is_off)
  83. assert(iter.item.same_as("B"))
  84. iter.next
  85. assert(not iter.is_off)
  86. assert(iter.item.same_as("C"))
  87. iter.next
  88. assert(iter.is_off)
  89. end
  90. end -- class TEST_AVL
  91. --
  92. -- ------------------------------------------------------------------------------------------------------------------------------
  93. -- Copyright notice below. Please read.
  94. --
  95. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  96. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  97. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  98. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  99. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  100. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  101. --
  102. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  103. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  104. --
  105. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  106. --
  107. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  108. -- ------------------------------------------------------------------------------------------------------------------------------