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

/test/lib/numeric/mutable_big_integer/test_mutable_big_integer13.e

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