/test/lib/storage/collection/test_array2.e

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