/test/lib/numeric/mutable_big_integer/test_mutable_big_integer4.e

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