PageRenderTime 10ms CodeModel.GetById 7ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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