/test/lib/numeric/mutable_big_integer/test_mutable_big_integer9.e

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