/test/lib/numeric/mutable_big_integer/test_mutable_big_integer13.e

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