/test/lib/numeric/mutable_big_integer/test_mutable_big_integer7.e

http://github.com/tybor/Liberty · Specman e · 165 lines · 131 code · 8 blank · 26 comment · 3 complexity · 55b19f9874ee2d9147895c640a1106be 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_INTEGER7
  5. --
  6. -- Testing feature `subtract' and 'subtract_to'.
  7. --
  8. insert
  9. ANY
  10. PLATFORM
  11. create {}
  12. make
  13. feature {ANY}
  14. make
  15. do
  16. check_subtract(0, 0)
  17. check_subtract(1, 0)
  18. check_subtract(1, 1)
  19. check_subtract(2, 0)
  20. check_subtract(2, 1)
  21. check_subtract(3, 0)
  22. check_subtract(3, 1)
  23. check_subtract(3, 2)
  24. check_subtract(3, 3)
  25. check_subtract(Maximum_integer - 3, 0)
  26. check_subtract(Maximum_integer - 3, 1)
  27. check_subtract(Maximum_integer - 3, 2)
  28. check_subtract(Maximum_integer - 3, 3)
  29. check_subtract(Maximum_integer, 0)
  30. check_subtract(Maximum_integer, 1)
  31. check_subtract(Maximum_integer, 2)
  32. check_subtract(Maximum_integer, 3)
  33. check_subtract(Maximum_integer, Maximum_integer.to_integer_64)
  34. check_subtract(Maximum_integer, Maximum_integer.to_integer_64 + 1)
  35. check_subtract(Maximum_integer, Maximum_integer.to_integer_64 + 2)
  36. check_subtract(Maximum_integer, Maximum_integer.to_integer_64 + 3)
  37. check_subtract(Maximum_integer, Maximum_integer.to_integer_64 + 4)
  38. check_subtract(Maximum_integer_64 - 3, 0)
  39. check_subtract(Maximum_integer_64 - 3, 1)
  40. check_subtract(Maximum_integer_64 - 3, 2)
  41. check_subtract(Maximum_integer_64 - 3, 3)
  42. end
  43. count: INTEGER
  44. assert (b: BOOLEAN)
  45. do
  46. count := count + 1
  47. if not b then
  48. sedb_breakpoint
  49. io.put_string("TEST_MUTABLE_BIG_INTEGER7 : ERROR Test # ")
  50. io.put_integer(count)
  51. io.put_string("%N")
  52. end
  53. end
  54. check_subtract (a, b: INTEGER_64)
  55. do
  56. check_subtract2(a, b)
  57. check_subtract2(b, a)
  58. check_subtract2(a, a)
  59. check_subtract2(b, b)
  60. check_subtract2(-a, b)
  61. check_subtract2(b, -a)
  62. check_subtract2(a, -b)
  63. check_subtract2(-b, a)
  64. check_subtract2(-a, -b)
  65. check_subtract2(-b, -a)
  66. end
  67. check_subtract2 (a, b: INTEGER_64)
  68. local
  69. c, v: INTEGER_64; mbia, mbib, mbic: MUTABLE_BIG_INTEGER
  70. do
  71. -- subtract
  72. create mbia.from_integer_64(a)
  73. create mbib.from_integer_64(b)
  74. mbia.subtract(mbib)
  75. if a = b then
  76. v := mbia.to_integer_64
  77. check
  78. v = 0
  79. end
  80. assert(v = 0)
  81. v := mbib.to_integer_64
  82. check
  83. v = b
  84. end
  85. assert(v = b)
  86. else
  87. c := a - b
  88. v := mbia.to_integer_64
  89. check
  90. v = c
  91. end
  92. assert(v = c)
  93. v := mbib.to_integer_64
  94. check
  95. v = b
  96. end
  97. assert(v = b)
  98. end
  99. -- subtract_to
  100. create mbia.from_integer_64(a)
  101. create mbib.from_integer_64(b)
  102. create mbic.from_integer(0)
  103. mbia.subtract_to(mbib, mbic)
  104. if a = b then
  105. v := mbia.to_integer_64
  106. check
  107. v = a
  108. end
  109. assert(v = a)
  110. v := mbib.to_integer_64
  111. check
  112. v = b
  113. end
  114. assert(v = b)
  115. v := mbic.to_integer_64
  116. check
  117. v = 0
  118. end
  119. assert(v = 0)
  120. else
  121. c := a - b
  122. v := mbia.to_integer_64
  123. check
  124. v = a
  125. end
  126. assert(v = a)
  127. v := mbib.to_integer_64
  128. check
  129. v = b
  130. end
  131. assert(v = b)
  132. v := mbic.to_integer_64
  133. check
  134. v = c
  135. end
  136. assert(v = c)
  137. end
  138. end
  139. end -- class TEST_MUTABLE_BIG_INTEGER7
  140. --
  141. -- ------------------------------------------------------------------------------------------------------------------------------
  142. -- Copyright notice below. Please read.
  143. --
  144. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  145. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  146. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  147. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  148. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  149. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  150. --
  151. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  152. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  153. --
  154. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  155. --
  156. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  157. -- ------------------------------------------------------------------------------------------------------------------------------