/test/lib/numeric/mutable_big_integer/test_mutable_big_integer8.e

http://github.com/tybor/Liberty · Specman e · 108 lines · 73 code · 7 blank · 28 comment · 1 complexity · e30307a2e8e14116b7e372af84a209e7 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_MUTABLE_BIG_INTEGER8
  5. --
  6. -- Testing features `shift_left' and `shift_right'.
  7. --
  8. create {}
  9. make
  10. feature {ANY}
  11. make
  12. local
  13. step: INTEGER
  14. do
  15. from
  16. step := 1
  17. until
  18. step >= 62
  19. loop
  20. shift_left_then_come_back(step)
  21. step := step + 1
  22. end
  23. end
  24. shift_left_then_come_back (step: INTEGER)
  25. require
  26. step.in_range(0, power_2_memory.upper - 1)
  27. local
  28. mbia: MUTABLE_BIG_INTEGER; i: INTEGER
  29. do
  30. create mbia.from_integer_64(1)
  31. i := 0
  32. -- Shifting left by `step' to reach the greatest `power_2_memory':
  33. from
  34. until
  35. i > 59 -- *** WE SHOULD BE ABLE TO GO TO power_2_memory.upper *** BUG
  36. loop
  37. assert(mbia.to_string.is_equal(power_2_memory.item(i).to_string))
  38. mbia.shift_left(step)
  39. i := i + step
  40. end
  41. -- Shifting right by `step' to come back to 0:
  42. from
  43. until
  44. i = 0
  45. loop
  46. i := i - step
  47. mbia.shift_right(step)
  48. assert(mbia.to_string.is_equal(power_2_memory.item(i).to_string))
  49. end
  50. end
  51. count: INTEGER
  52. assert (b: BOOLEAN)
  53. do
  54. count := count + 1
  55. if not b then
  56. sedb_breakpoint
  57. io.put_string("TEST_MUTABLE_BIG_INTEGER8 : ERROR Test # ")
  58. io.put_integer(count)
  59. io.put_string("%N")
  60. end
  61. end
  62. power_2_memory: FAST_ARRAY[INTEGER_64]
  63. -- The associated power 2 value at the corresponding index.
  64. -- (Valid for range [2^0 .. 2^62].)
  65. local
  66. i: INTEGER; v: INTEGER_64
  67. once
  68. from
  69. create Result.with_capacity(64)
  70. i := 0
  71. v := 1
  72. until
  73. v < 0
  74. loop
  75. Result.add_last(v)
  76. i := i + 1
  77. v := v #* 2
  78. end
  79. check
  80. Result.upper = 62
  81. end
  82. end
  83. end -- class TEST_MUTABLE_BIG_INTEGER8
  84. --
  85. -- ------------------------------------------------------------------------------------------------------------------------------
  86. -- Copyright notice below. Please read.
  87. --
  88. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  89. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  90. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  91. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  92. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  93. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  94. --
  95. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  96. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  97. --
  98. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  99. --
  100. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  101. -- ------------------------------------------------------------------------------------------------------------------------------