PageRenderTime 21ms CodeModel.GetById 18ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/test/lib/numeric/mutable_big_integer/test_mutable_big_integer1.e

http://github.com/tybor/Liberty
Specman e | 112 lines | 83 code | 5 blank | 24 comment | 0 complexity | cad7fe414d4d8ca96c9a29723bb2f3e5 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_INTEGER1
  5   --
  6   -- Testing from_integer/to_integer/is_integer/is_zero/negate
  7   --
  8
  9insert
 10   ARGUMENTS
 11   PLATFORM
 12   EIFFELTEST_TOOLS
 13
 14create {}
 15   make
 16
 17feature {ANY}
 18   make
 19      local
 20         mbi1: MUTABLE_BIG_INTEGER; v: INTEGER
 21      do
 22         create mbi1.from_integer(0)
 23         assert(mbi1.is_integer_32)
 24         assert(mbi1.is_zero)
 25         assert(not mbi1.is_one)
 26         assert(mbi1.is_even)
 27         assert(not mbi1.is_odd)
 28         assert(mbi1.to_string.is_equal("0"))
 29         assert(not mbi1.is_negative)
 30         mbi1.negate
 31         assert(not mbi1.is_negative)
 32         create mbi1.from_integer(2)
 33         assert(mbi1.to_integer_32 = 2)
 34         assert(not mbi1.is_zero)
 35         assert(not mbi1.is_negative)
 36         mbi1.negate
 37         assert(mbi1.is_negative)
 38         create mbi1.from_integer(1)
 39         assert(mbi1.to_integer_32 = 1)
 40         assert(not mbi1.is_zero)
 41         assert(mbi1.is_one)
 42         assert(not mbi1.is_even)
 43         assert(mbi1.is_odd)
 44         create mbi1.from_integer(-1)
 45         assert(mbi1.to_integer_32 = -1)
 46         assert(not mbi1.is_zero)
 47         create mbi1.from_integer(-2)
 48         assert(mbi1.to_integer_32 = -2)
 49         assert(not mbi1.is_zero)
 50         assert(not mbi1.is_one)
 51         assert(mbi1.is_even)
 52         assert(not mbi1.is_odd)
 53         create mbi1.from_integer(Maximum_integer)
 54         assert(mbi1.to_integer_32 = Maximum_integer)
 55         assert(not mbi1.is_zero)
 56         create mbi1.from_integer(Minimum_integer)
 57         assert(mbi1.to_integer_32 = Minimum_integer)
 58         assert(not mbi1.is_zero)
 59         v := Minimum_integer + 1
 60         create mbi1.from_integer(v)
 61         assert(mbi1.to_integer_32 = v)
 62         assert(not mbi1.is_zero)
 63         v := Maximum_integer - 1
 64         create mbi1.from_integer(v)
 65         assert(mbi1.to_integer_32 = v)
 66         assert(not mbi1.is_zero)
 67         check_range(Minimum_integer, -2147483600)
 68         check_range(-128, 128)
 69         check_range(2147483600, Maximum_integer)
 70         create mbi1.from_integer_64(2147483648)
 71         assert(not mbi1.is_integer_32)
 72         create mbi1.from_integer_64(-2147483649)
 73         assert(not mbi1.is_integer_32)
 74      end
 75
 76   check_range (min, max: INTEGER)
 77      require
 78         min < max
 79      local
 80         i, mem: INTEGER; mbi: MUTABLE_BIG_INTEGER
 81      do
 82         from
 83            i := min
 84         until
 85            i = max
 86         loop
 87            mem := i
 88            create mbi.from_integer(mem)
 89            assert(mem = mbi.to_integer_32)
 90            i := i + 1
 91         end
 92      end
 93
 94end -- class TEST_MUTABLE_BIG_INTEGER1
 95--
 96-- ------------------------------------------------------------------------------------------------------------------------------
 97-- Copyright notice below. Please read.
 98--
 99-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
100-- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
101-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
102-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
103-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
104-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
105--
106-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P.       - University of Nancy 1 - FRANCE
107-- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
108--
109-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
110--
111-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
112-- ------------------------------------------------------------------------------------------------------------------------------