PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/test/lib/numeric/mutable_big_integer/test_mutable_big_integer7.e

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