/test/lib/numeric/mutable_big_integer/aux_mutable_big_integer1.e

http://github.com/tybor/Liberty · Specman e · 144 lines · 104 code · 8 blank · 32 comment · 4 complexity · 8f61db25730984fc0fde3b50c3b6563b 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 AUX_MUTABLE_BIG_INTEGER1
  5. -- Use `numbers*' first to make tests.
  6. -- `check_and_restore(numbers*)' test if `numbers*' is corrupted or
  7. -- not and restore it.
  8. -- Use `restore(numbers*)' to restore `numbers*'.
  9. insert
  10. PLATFORM
  11. EIFFELTEST_TOOLS
  12. feature {}
  13. numbers_check: FAST_ARRAY[MUTABLE_BIG_INTEGER]
  14. once
  15. Result := {FAST_ARRAY[MUTABLE_BIG_INTEGER] << create {MUTABLE_BIG_INTEGER}.from_integer(0), create {MUTABLE_BIG_INTEGER}.from_integer(1), create {MUTABLE_BIG_INTEGER}.from_integer(-1), create {MUTABLE_BIG_INTEGER}.from_integer(2), create {MUTABLE_BIG_INTEGER}.from_integer(-2), create {MUTABLE_BIG_INTEGER}.from_integer(3), create {MUTABLE_BIG_INTEGER}.from_integer(-3), create {MUTABLE_BIG_INTEGER}.from_integer(1000), create {MUTABLE_BIG_INTEGER}.from_integer(-1000), create {MUTABLE_BIG_INTEGER}.from_integer(1000000000), create {MUTABLE_BIG_INTEGER}.from_integer(-1000000000), create {MUTABLE_BIG_INTEGER}.from_integer(Maximum_integer), create {MUTABLE_BIG_INTEGER}.from_integer(-Maximum_integer), create {MUTABLE_BIG_INTEGER}.from_integer_64(-Minimum_integer.to_integer_64), create {MUTABLE_BIG_INTEGER}.from_integer(Minimum_integer), create {MUTABLE_BIG_INTEGER}.from_integer_64(Maximum_integer_64), create {MUTABLE_BIG_INTEGER}.from_integer_64(-Maximum_integer_64), create {MUTABLE_BIG_INTEGER}.from_string("9223372036854775808"), create {MUTABLE_BIG_INTEGER}.from_integer_64(Minimum_integer_64
  16. -- -Minimum_integer_64
  17. ), create {MUTABLE_BIG_INTEGER}.from_string("1000000000000000000"), create {MUTABLE_BIG_INTEGER}.from_string("-1000000000000000000"
  18. -- 10^18
  19. ), create {MUTABLE_BIG_INTEGER}.from_string("1000000000000000000000000000000" -- -10^18
  20. ), create {MUTABLE_BIG_INTEGER}.from_string("-1000000000000000000000000000000" -- 10^30
  21. ), create {MUTABLE_BIG_INTEGER}.from_string("100000000000000000000000000000000000000000000000000" -- -10^30
  22. ), create {MUTABLE_BIG_INTEGER}.from_string("-100000000000000000000000000000000000000000000000000" -- 10^50
  23. ), create {MUTABLE_BIG_INTEGER}.from_string("99999999999999999999999999999999999999999999999999" -- -10^50
  24. ), create {MUTABLE_BIG_INTEGER}.from_string("-99999999999999999999999999999999999999999999999999" -- 10^50 - 1
  25. ), create {MUTABLE_BIG_INTEGER}.from_string("100000000000000000000000000000000000000000000000001" -- -(10^50 - 1)
  26. ), create {MUTABLE_BIG_INTEGER}.from_string("-100000000000000000000000000000000000000000000000001" -- 10^50 + 1
  27. ) -- -(10^50 + 1)
  28. >> }
  29. end
  30. feature {ANY}
  31. numbers1: FAST_ARRAY[MUTABLE_BIG_INTEGER]
  32. -- Give an independant copy of `numbers_check'.
  33. local
  34. i: INTEGER
  35. once
  36. create Result.with_capacity(numbers_check.capacity)
  37. from
  38. i := numbers_check.lower
  39. until
  40. i > numbers_check.upper
  41. loop
  42. Result.add_last(numbers_check.item(i).twin)
  43. i := i + 1
  44. end
  45. end
  46. numbers2: FAST_ARRAY[MUTABLE_BIG_INTEGER]
  47. -- Give another independant copy of `numbers_check'.
  48. local
  49. i: INTEGER
  50. once
  51. create Result.with_capacity(numbers_check.capacity)
  52. from
  53. i := numbers_check.lower
  54. until
  55. i > numbers_check.upper
  56. loop
  57. Result.add_last(numbers_check.item(i).twin)
  58. end
  59. end
  60. restore (n: FAST_ARRAY[MUTABLE_BIG_INTEGER])
  61. -- Restore `n' (which is `number1' or `number2'.
  62. require
  63. n = numbers1 or n = numbers2
  64. local
  65. i: INTEGER
  66. do
  67. from
  68. i := numbers_check.lower
  69. until
  70. i > numbers_check.upper
  71. loop
  72. if numbers_check.item(i).is_equal(n.item(i)) then
  73. if n.item(i) = Void then
  74. n.put(numbers_check.item(i).twin, i)
  75. else
  76. n.item(i).copy(numbers_check.item(i))
  77. end
  78. end
  79. i := i + 1
  80. end
  81. end
  82. verify (n: FAST_ARRAY[MUTABLE_BIG_INTEGER])
  83. -- Are the numbers original ? Restore the bad number.
  84. local
  85. i: INTEGER
  86. do
  87. from
  88. i := numbers_check.lower
  89. until
  90. i > numbers_check.upper
  91. loop
  92. assert(numbers_check.item(i).is_equal(n.item(i)))
  93. i := i + 1
  94. end
  95. end
  96. verify_and_restore (n: FAST_ARRAY[MUTABLE_BIG_INTEGER])
  97. -- Are the numbers original ? Restore the bad number.
  98. local
  99. i: INTEGER; b: BOOLEAN
  100. do
  101. from
  102. i := numbers_check.lower
  103. until
  104. i > numbers_check.upper
  105. loop
  106. b := numbers_check.item(i).is_equal(n.item(i))
  107. assert(b)
  108. if b then
  109. if n.item(i) = Void then
  110. n.put(numbers_check.item(i).twin, i)
  111. else
  112. n.item(i).copy(numbers_check.item(i))
  113. end
  114. end
  115. i := i + 1
  116. end
  117. end
  118. end -- class AUX_MUTABLE_BIG_INTEGER1
  119. --
  120. -- ------------------------------------------------------------------------------------------------------------------------------
  121. -- Copyright notice below. Please read.
  122. --
  123. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  124. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  125. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  126. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  127. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  128. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  129. --
  130. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  131. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  132. --
  133. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  134. --
  135. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  136. -- ------------------------------------------------------------------------------------------------------------------------------