/test/lib/storage/collection/test_index_of2.e

http://github.com/tybor/Liberty · Specman e · 146 lines · 117 code · 4 blank · 25 comment · 0 complexity · 216d5fa8a8151045a1fd43d0ed58ee66 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_INDEX_OF2
  5. insert
  6. EIFFELTEST_TOOLS
  7. create {}
  8. make
  9. feature {ANY}
  10. make
  11. local
  12. collection: COLLECTION[CHARACTER]
  13. do
  14. collection := {FAST_ARRAY[CHARACTER] << 'a', 'b', 'a', 'b', 'b' >> }
  15. assert(collection.index_of('a', 0) = 0)
  16. assert(collection.index_of('a', 1) = 2)
  17. assert(collection.index_of('a', 2) = 2)
  18. assert(collection.index_of('a', 3) = 5)
  19. assert(collection.fast_index_of('a', 0) = 0)
  20. assert(collection.fast_index_of('a', 1) = 2)
  21. assert(collection.fast_index_of('a', 2) = 2)
  22. assert(collection.fast_index_of('a', 3) = 5)
  23. assert(collection.fast_last_index_of('b') = 4)
  24. assert(collection.last_index_of('b') = 4)
  25. assert(collection.fast_last_index_of('a') = 2)
  26. assert(collection.last_index_of('a') = 2)
  27. assert(collection.fast_reverse_index_of('b', 3) = 3)
  28. assert(collection.reverse_index_of('b', 3) = 3)
  29. assert(collection.fast_reverse_index_of('a', 0) = 0)
  30. assert(collection.reverse_index_of('a', 0) = 0)
  31. assert(collection.fast_last_index_of('c') = -1)
  32. assert(collection.last_index_of('c') = -1)
  33. assert(collection.fast_reverse_index_of('c', 0) = -1)
  34. assert(collection.reverse_index_of('c', 0) = -1)
  35. --
  36. collection := {ARRAY[CHARACTER] 0, << 'a', 'b', 'a', 'b', 'b' >> }
  37. assert(collection.index_of('a', 0) = 0)
  38. assert(collection.index_of('a', 1) = 2)
  39. assert(collection.index_of('a', 2) = 2)
  40. assert(collection.index_of('a', 3) = 5)
  41. assert(collection.fast_index_of('a', 0) = 0)
  42. assert(collection.fast_index_of('a', 1) = 2)
  43. assert(collection.fast_index_of('a', 2) = 2)
  44. assert(collection.fast_index_of('a', 3) = 5)
  45. assert(collection.fast_last_index_of('b') = 4)
  46. assert(collection.last_index_of('b') = 4)
  47. assert(collection.fast_last_index_of('a') = 2)
  48. assert(collection.last_index_of('a') = 2)
  49. assert(collection.fast_reverse_index_of('b', 3) = 3)
  50. assert(collection.reverse_index_of('b', 3) = 3)
  51. assert(collection.fast_reverse_index_of('a', 0) = 0)
  52. assert(collection.reverse_index_of('a', 0) = 0)
  53. assert(collection.fast_last_index_of('c') = -1)
  54. assert(collection.last_index_of('c') = -1)
  55. assert(collection.fast_reverse_index_of('c', 0) = -1)
  56. assert(collection.reverse_index_of('c', 0) = -1)
  57. --
  58. collection := {RING_ARRAY[CHARACTER] 0, << 'a', 'b', 'a', 'b', 'b' >> }
  59. assert(collection.index_of('a', 0) = 0)
  60. assert(collection.index_of('a', 1) = 2)
  61. assert(collection.index_of('a', 2) = 2)
  62. assert(collection.index_of('a', 3) = 5)
  63. assert(collection.fast_index_of('a', 0) = 0)
  64. assert(collection.fast_index_of('a', 1) = 2)
  65. assert(collection.fast_index_of('a', 2) = 2)
  66. assert(collection.fast_index_of('a', 3) = 5)
  67. assert(collection.fast_last_index_of('b') = 4)
  68. assert(collection.last_index_of('b') = 4)
  69. assert(collection.fast_last_index_of('a') = 2)
  70. assert(collection.last_index_of('a') = 2)
  71. assert(collection.fast_reverse_index_of('b', 3) = 3)
  72. assert(collection.reverse_index_of('b', 3) = 3)
  73. assert(collection.fast_reverse_index_of('a', 0) = 0)
  74. assert(collection.reverse_index_of('a', 0) = 0)
  75. assert(collection.fast_last_index_of('c') = -1)
  76. assert(collection.last_index_of('c') = -1)
  77. assert(collection.fast_reverse_index_of('c', 0) = -1)
  78. assert(collection.reverse_index_of('c', 0) = -1)
  79. --
  80. collection := {LINKED_LIST[CHARACTER] << 'a', 'b', 'a', 'b', 'b' >> }
  81. assert(collection.index_of('a', 1) = 1)
  82. assert(collection.index_of('a', 2) = 3)
  83. assert(collection.index_of('a', 3) = 3)
  84. assert(collection.index_of('a', 4) = 6)
  85. assert(collection.fast_index_of('a', 1) = 1)
  86. assert(collection.fast_index_of('a', 2) = 3)
  87. assert(collection.fast_index_of('a', 3) = 3)
  88. assert(collection.fast_index_of('a', 4) = 6)
  89. assert(collection.fast_last_index_of('b') = 5)
  90. assert(collection.last_index_of('b') = 5)
  91. assert(collection.fast_last_index_of('a') = 3)
  92. assert(collection.last_index_of('a') = 3)
  93. assert(collection.fast_reverse_index_of('b', 4) = 4)
  94. assert(collection.reverse_index_of('b', 4) = 4)
  95. assert(collection.fast_reverse_index_of('a', 1) = 1)
  96. assert(collection.reverse_index_of('a', 1) = 1)
  97. assert(collection.fast_last_index_of('c') = 0)
  98. assert(collection.last_index_of('c') = 0)
  99. assert(collection.fast_reverse_index_of('c', 1) = 0)
  100. assert(collection.reverse_index_of('c', 1) = 0)
  101. --
  102. collection := {TWO_WAY_LINKED_LIST[CHARACTER] << 'a', 'b', 'a', 'b', 'b' >> }
  103. assert(collection.index_of('a', 1) = 1)
  104. assert(collection.index_of('a', 2) = 3)
  105. assert(collection.index_of('a', 3) = 3)
  106. assert(collection.index_of('a', 4) = 6)
  107. assert(collection.fast_index_of('a', 1) = 1)
  108. assert(collection.fast_index_of('a', 2) = 3)
  109. assert(collection.fast_index_of('a', 3) = 3)
  110. assert(collection.fast_index_of('a', 4) = 6)
  111. assert(collection.fast_last_index_of('b') = 5)
  112. assert(collection.last_index_of('b') = 5)
  113. assert(collection.fast_last_index_of('a') = 3)
  114. assert(collection.last_index_of('a') = 3)
  115. assert(collection.fast_reverse_index_of('b', 4) = 4)
  116. assert(collection.reverse_index_of('b', 4) = 4)
  117. assert(collection.fast_reverse_index_of('a', 1) = 1)
  118. assert(collection.reverse_index_of('a', 1) = 1)
  119. assert(collection.fast_last_index_of('c') = 0)
  120. assert(collection.last_index_of('c') = 0)
  121. assert(collection.fast_reverse_index_of('c', 1) = 0)
  122. assert(collection.reverse_index_of('c', 1) = 0)
  123. end
  124. end -- class TEST_INDEX_OF2
  125. --
  126. -- ------------------------------------------------------------------------------------------------------------------------------
  127. -- Copyright notice below. Please read.
  128. --
  129. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  130. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  131. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  132. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  133. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  134. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  135. --
  136. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  137. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  138. --
  139. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  140. --
  141. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  142. -- ------------------------------------------------------------------------------------------------------------------------------