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

/test/lib/numeric/mutable_big_integer/test_mutable_big_integer2.e

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