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

/test/lib/numeric/mutable_big_integer/test_mutable_big_integer8.e

http://github.com/tybor/Liberty
Specman e | 108 lines | 73 code | 7 blank | 28 comment | 1 complexity | e30307a2e8e14116b7e372af84a209e7 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_INTEGER8
  5   --
  6   -- Testing features `shift_left' and `shift_right'.
  7   --
  8
  9create {}
 10   make
 11
 12feature {ANY}
 13   make
 14      local
 15         step: INTEGER
 16      do
 17         from
 18            step := 1
 19         until
 20            step >= 62
 21         loop
 22            shift_left_then_come_back(step)
 23            step := step + 1
 24         end
 25      end
 26
 27   shift_left_then_come_back (step: INTEGER)
 28      require
 29         step.in_range(0, power_2_memory.upper - 1)
 30      local
 31         mbia: MUTABLE_BIG_INTEGER; i: INTEGER
 32      do
 33         create mbia.from_integer_64(1)
 34         i := 0
 35         -- Shifting left by `step' to reach the greatest `power_2_memory':
 36         from
 37         until
 38            i > 59 -- *** WE SHOULD BE ABLE TO GO TO power_2_memory.upper *** BUG
 39         loop
 40            assert(mbia.to_string.is_equal(power_2_memory.item(i).to_string))
 41            mbia.shift_left(step)
 42            i := i + step
 43         end
 44         -- Shifting right by `step' to come back to 0:
 45         from
 46         until
 47            i = 0
 48         loop
 49            i := i - step
 50            mbia.shift_right(step)
 51            assert(mbia.to_string.is_equal(power_2_memory.item(i).to_string))
 52         end
 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_INTEGER8 : ERROR Test # ")
 63            io.put_integer(count)
 64            io.put_string("%N")
 65         end
 66      end
 67
 68   power_2_memory: FAST_ARRAY[INTEGER_64]
 69         -- The associated power 2 value at the corresponding index.
 70         -- (Valid for range [2^0 .. 2^62].)
 71      local
 72         i: INTEGER; v: INTEGER_64
 73      once
 74         from
 75            create Result.with_capacity(64)
 76            i := 0
 77            v := 1
 78         until
 79            v < 0
 80         loop
 81            Result.add_last(v)
 82            i := i + 1
 83            v := v #* 2
 84         end
 85         check
 86            Result.upper = 62
 87         end
 88      end
 89
 90end -- class TEST_MUTABLE_BIG_INTEGER8
 91--
 92-- ------------------------------------------------------------------------------------------------------------------------------
 93-- Copyright notice below. Please read.
 94--
 95-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
 96-- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
 97-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
 98-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
 99-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
100-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
101--
102-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P.       - University of Nancy 1 - FRANCE
103-- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
104--
105-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
106--
107-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
108-- ------------------------------------------------------------------------------------------------------------------------------