/test/lib/storage/collection/test_slice1.e

http://github.com/tybor/Liberty · Specman e · 88 lines · 61 code · 6 blank · 21 comment · 0 complexity · 2105b433fd2ea9d1f4ff6216a4ea720b 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_SLICE1
  5. insert
  6. EIFFELTEST_TOOLS
  7. create {}
  8. make
  9. feature {ANY}
  10. make
  11. local
  12. model2: FAST_ARRAY[INTEGER]; model3: ARRAY[INTEGER]
  13. do
  14. test({ARRAY[INTEGER] 1, << 1, 2, 3, 4 >> })
  15. create model2.from_collection({ARRAY[INTEGER] 1, << 1, 2, 3, 4 >> })
  16. test(model2)
  17. create model3.make(-2, 1)
  18. model3.put(1, -2)
  19. model3.put(2, -1)
  20. model3.put(3, 0)
  21. model3.put(4, 1)
  22. test(model3)
  23. end
  24. test (model: COLLECTION[INTEGER])
  25. local
  26. a: ARRAY[INTEGER]; fa: FAST_ARRAY[INTEGER]; ll: LINKED_LIST[INTEGER]; l2l: TWO_WAY_LINKED_LIST[INTEGER]
  27. do
  28. create a.from_collection(model)
  29. test1(a)
  30. create fa.from_collection(model)
  31. test1(fa)
  32. create ll.from_collection(model)
  33. test1(ll)
  34. create l2l.from_collection(model)
  35. test1(l2l)
  36. end
  37. feature {}
  38. test1 (model: COLLECTION[INTEGER])
  39. local
  40. slice: like model
  41. do
  42. slice := model.slice(model.lower, model.lower)
  43. assert(slice.last = 1)
  44. slice := model.slice(model.lower, model.lower + 1)
  45. assert(slice.first = 1)
  46. assert(slice.last = 2)
  47. slice := model.slice(model.lower + 1, model.lower + 1)
  48. assert(slice.first = 2)
  49. slice := model.slice(model.lower + 1, model.lower + 2)
  50. assert(slice.first = 2)
  51. assert(slice.last = 3)
  52. slice := model.slice(model.upper, model.upper)
  53. assert(slice.last = 4)
  54. slice := model.slice(model.upper - 1, model.upper)
  55. assert(slice.first = 3)
  56. assert(slice.last = 4)
  57. slice := model.slice(model.lower, model.upper)
  58. assert(slice.is_equal(model))
  59. slice := model.slice(model.lower, model.lower - 1)
  60. assert(slice.is_empty)
  61. slice := model.slice(model.upper, model.upper - 1)
  62. assert(slice.is_empty)
  63. end
  64. end -- class TEST_SLICE1
  65. --
  66. -- ------------------------------------------------------------------------------------------------------------------------------
  67. -- Copyright notice below. Please read.
  68. --
  69. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  70. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  71. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  72. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  73. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  74. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  75. --
  76. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  77. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  78. --
  79. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  80. --
  81. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  82. -- ------------------------------------------------------------------------------------------------------------------------------