/test/lib/storage/collection/test_subarray1.e

http://github.com/tybor/Liberty · Specman e · 121 lines · 91 code · 8 blank · 22 comment · 1 complexity · 0b44a4e2f190ccf3cb9d9df04142b05a 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_SUBARRAY1
  5. create {}
  6. make
  7. feature {ANY}
  8. make
  9. local
  10. model2: FAST_ARRAY[INTEGER_8]; model3: ARRAY[INTEGER_8]
  11. do
  12. test({ARRAY[INTEGER_8] 1, << 1, 2, 3, 4 >> })
  13. create model2.from_collection({ARRAY[INTEGER_8] 1, << 1, 2, 3, 4 >> })
  14. test(model2)
  15. create model3.make(-2, 1)
  16. model3.put(1, -2)
  17. model3.put(2, -1)
  18. model3.put(3, 0)
  19. model3.put(4, 1)
  20. test(model3)
  21. end
  22. test (model: COLLECTION[INTEGER_8])
  23. local
  24. a: ARRAY[INTEGER_8]; fa: FAST_ARRAY[INTEGER_8]
  25. do
  26. create a.from_collection(model)
  27. test1_array(a)
  28. create fa.from_collection(model)
  29. test1_fast_array(fa)
  30. end
  31. feature {}
  32. test1_array (model: ARRAY[INTEGER_8])
  33. local
  34. subarray: like model
  35. do
  36. subarray := model.subarray(model.lower, model.lower)
  37. assert(subarray.last = 1)
  38. assert(subarray.first = 1)
  39. subarray := model.subarray(model.lower, model.lower + 1)
  40. assert(subarray.first = 1)
  41. assert(subarray.last = 2)
  42. subarray := model.subarray(model.lower + 1, model.lower + 1)
  43. assert(subarray.first = 2)
  44. subarray := model.subarray(model.lower + 1, model.lower + 2)
  45. assert(subarray.first = 2)
  46. assert(subarray.last = 3)
  47. subarray := model.subarray(model.upper, model.upper)
  48. assert(subarray.last = 4)
  49. subarray := model.subarray(model.upper - 1, model.upper)
  50. assert(subarray.first = 3)
  51. assert(subarray.last = 4)
  52. subarray := model.subarray(model.lower, model.upper)
  53. assert(subarray.is_equal(model))
  54. subarray := model.subarray(model.upper, model.upper - 1)
  55. assert(subarray.is_empty)
  56. end
  57. test1_fast_array (model: FAST_ARRAY[INTEGER_8])
  58. local
  59. subarray: like model
  60. do
  61. subarray := model.subarray(model.lower, model.lower)
  62. assert(subarray.last = 1)
  63. assert(subarray.first = 1)
  64. subarray := model.subarray(model.lower, model.lower + 1)
  65. assert(subarray.first = 1)
  66. assert(subarray.last = 2)
  67. subarray := model.subarray(model.lower + 1, model.lower + 1)
  68. assert(subarray.first = 2)
  69. subarray := model.subarray(model.lower + 1, model.lower + 2)
  70. assert(subarray.first = 2)
  71. assert(subarray.last = 3)
  72. subarray := model.subarray(model.upper, model.upper)
  73. assert(subarray.last = 4)
  74. subarray := model.subarray(model.upper - 1, model.upper)
  75. assert(subarray.first = 3)
  76. assert(subarray.last = 4)
  77. subarray := model.subarray(model.lower, model.upper)
  78. assert(subarray.is_equal(model))
  79. subarray := model.subarray(model.upper, model.upper - 1)
  80. assert(subarray.is_empty)
  81. end
  82. feature {}
  83. assert (b: BOOLEAN)
  84. do
  85. cpt := cpt + 1
  86. if not b then
  87. std_output.put_string("TEST_SUBARRAY1: ERROR Test # ")
  88. std_output.put_integer(cpt)
  89. std_output.put_string("%N")
  90. else
  91. -- std_output.put_string("Yes%N")
  92. end
  93. end
  94. cpt: INTEGER
  95. end -- class TEST_SUBARRAY1
  96. --
  97. -- ------------------------------------------------------------------------------------------------------------------------------
  98. -- Copyright notice below. Please read.
  99. --
  100. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  101. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  102. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  103. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  104. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  105. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  106. --
  107. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  108. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  109. --
  110. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  111. --
  112. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  113. -- ------------------------------------------------------------------------------------------------------------------------------