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

/test/lib/numeric/mutable_big_integer/test_mutable_big_integer3.e

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