PageRenderTime 19ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

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