/test/lib/numeric/mutable_big_integer/test_mutable_big_integer7bis.e

http://github.com/tybor/Liberty · Specman e · 148 lines · 111 code · 9 blank · 28 comment · 1 complexity · 5b66e0b261a17495b35ef42bccf9ac30 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_INTEGER7BIS
  5. --
  6. -- Testing feature `add' and `add_to'.
  7. --
  8. insert
  9. ANY
  10. PLATFORM
  11. create {}
  12. make
  13. feature {ANY}
  14. make
  15. do
  16. check_add(0, 0)
  17. check_add(1, 0)
  18. check_add(1, 1)
  19. check_add(2, 0)
  20. check_add(2, 1)
  21. check_add(3, 0)
  22. check_add(3, 1)
  23. check_add(3, 2)
  24. check_add(3, 3)
  25. check_add(Maximum_integer - 3, 0)
  26. check_add(Maximum_integer - 3, 1)
  27. check_add(Maximum_integer - 3, 2)
  28. check_add(Maximum_integer - 3, 3)
  29. check_add(Maximum_integer, 0)
  30. check_add(Maximum_integer, 1)
  31. check_add(Maximum_integer, 2)
  32. check_add(Maximum_integer, 3)
  33. check_add(Maximum_integer, Maximum_integer.to_integer_64)
  34. check_add(Maximum_integer, Maximum_integer.to_integer_64 + 1)
  35. check_add(Maximum_integer, Maximum_integer.to_integer_64 + 2)
  36. check_add(Maximum_integer, Maximum_integer.to_integer_64 + 3)
  37. check_add(Maximum_integer, Maximum_integer.to_integer_64 + 4)
  38. check_add_over64(Maximum_integer_64 - 3, 0)
  39. check_add_over64(Maximum_integer_64 - 3, 1)
  40. check_add_over64(Maximum_integer_64 - 3, 2)
  41. check_add_over64(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_INTEGER7bis : ERROR Test # ")
  50. io.put_integer(count)
  51. io.put_string("%N")
  52. end
  53. end
  54. check_add (a, b: INTEGER_64)
  55. do
  56. check_add2(a, b)
  57. check_add2(b, a)
  58. check_add2(a, a)
  59. check_add2(b, b)
  60. check_add2(-a, b)
  61. check_add2(b, -a)
  62. check_add2(a, -b)
  63. check_add2(-b, a)
  64. check_add2(-a, -b)
  65. check_add2(-b, -a)
  66. end
  67. check_add_over64 (a, b: INTEGER_64)
  68. do
  69. check_add2(a, b)
  70. check_add2(b, a)
  71. --check_add2(a, a)
  72. --check_add2(b, b)
  73. check_add2(-a, b)
  74. check_add2(b, -a)
  75. check_add2(a, -b)
  76. check_add2(-b, a)
  77. check_add2(-a, -b)
  78. check_add2(-b, -a)
  79. end
  80. check_add2 (a, b: INTEGER_64)
  81. local
  82. c, v: INTEGER_64; mbia, mbib, mbic: MUTABLE_BIG_INTEGER
  83. do
  84. -- test add
  85. create mbia.from_integer_64(a)
  86. create mbib.from_integer_64(b)
  87. mbia.add(mbib)
  88. c := a + b
  89. v := mbia.to_integer_64
  90. check
  91. v = c
  92. end
  93. assert(v = c)
  94. v := mbib.to_integer_64
  95. check
  96. v = b
  97. end
  98. assert(v = b)
  99. -- test add_to
  100. create mbia.from_integer_64(a)
  101. create mbib.from_integer_64(b)
  102. create mbic.from_integer(0)
  103. mbia.add_to(mbib, mbic)
  104. c := a + b
  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 = c
  118. end
  119. assert(v = c)
  120. end
  121. end -- class TEST_MUTABLE_BIG_INTEGER7BIS
  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. -- ------------------------------------------------------------------------------------------------------------------------------