/test/lib/numeric/mutable_big_integer/aux_mutable_big_integer1.e
Specman e | 144 lines | 104 code | 8 blank | 32 comment | 4 complexity | 8f61db25730984fc0fde3b50c3b6563b 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 AUX_MUTABLE_BIG_INTEGER1 5 -- Use `numbers*' first to make tests. 6 -- `check_and_restore(numbers*)' test if `numbers*' is corrupted or 7 -- not and restore it. 8 -- Use `restore(numbers*)' to restore `numbers*'. 9 10insert 11 PLATFORM 12 EIFFELTEST_TOOLS 13 14feature {} 15 numbers_check: FAST_ARRAY[MUTABLE_BIG_INTEGER] 16 once 17 Result := {FAST_ARRAY[MUTABLE_BIG_INTEGER] << create {MUTABLE_BIG_INTEGER}.from_integer(0), create {MUTABLE_BIG_INTEGER}.from_integer(1), create {MUTABLE_BIG_INTEGER}.from_integer(-1), create {MUTABLE_BIG_INTEGER}.from_integer(2), create {MUTABLE_BIG_INTEGER}.from_integer(-2), create {MUTABLE_BIG_INTEGER}.from_integer(3), create {MUTABLE_BIG_INTEGER}.from_integer(-3), create {MUTABLE_BIG_INTEGER}.from_integer(1000), create {MUTABLE_BIG_INTEGER}.from_integer(-1000), create {MUTABLE_BIG_INTEGER}.from_integer(1000000000), create {MUTABLE_BIG_INTEGER}.from_integer(-1000000000), create {MUTABLE_BIG_INTEGER}.from_integer(Maximum_integer), create {MUTABLE_BIG_INTEGER}.from_integer(-Maximum_integer), create {MUTABLE_BIG_INTEGER}.from_integer_64(-Minimum_integer.to_integer_64), create {MUTABLE_BIG_INTEGER}.from_integer(Minimum_integer), create {MUTABLE_BIG_INTEGER}.from_integer_64(Maximum_integer_64), create {MUTABLE_BIG_INTEGER}.from_integer_64(-Maximum_integer_64), create {MUTABLE_BIG_INTEGER}.from_string("9223372036854775808"), create {MUTABLE_BIG_INTEGER}.from_integer_64(Minimum_integer_64 18 -- -Minimum_integer_64 19 ), create {MUTABLE_BIG_INTEGER}.from_string("1000000000000000000"), create {MUTABLE_BIG_INTEGER}.from_string("-1000000000000000000" 20 -- 10^18 21 ), create {MUTABLE_BIG_INTEGER}.from_string("1000000000000000000000000000000" -- -10^18 22 ), create {MUTABLE_BIG_INTEGER}.from_string("-1000000000000000000000000000000" -- 10^30 23 ), create {MUTABLE_BIG_INTEGER}.from_string("100000000000000000000000000000000000000000000000000" -- -10^30 24 ), create {MUTABLE_BIG_INTEGER}.from_string("-100000000000000000000000000000000000000000000000000" -- 10^50 25 ), create {MUTABLE_BIG_INTEGER}.from_string("99999999999999999999999999999999999999999999999999" -- -10^50 26 ), create {MUTABLE_BIG_INTEGER}.from_string("-99999999999999999999999999999999999999999999999999" -- 10^50 - 1 27 ), create {MUTABLE_BIG_INTEGER}.from_string("100000000000000000000000000000000000000000000000001" -- -(10^50 - 1) 28 ), create {MUTABLE_BIG_INTEGER}.from_string("-100000000000000000000000000000000000000000000000001" -- 10^50 + 1 29 ) -- -(10^50 + 1) 30 >> } 31 end 32 33feature {ANY} 34 numbers1: FAST_ARRAY[MUTABLE_BIG_INTEGER] 35 -- Give an independant copy of `numbers_check'. 36 local 37 i: INTEGER 38 once 39 create Result.with_capacity(numbers_check.capacity) 40 from 41 i := numbers_check.lower 42 until 43 i > numbers_check.upper 44 loop 45 Result.add_last(numbers_check.item(i).twin) 46 i := i + 1 47 end 48 end 49 50 numbers2: FAST_ARRAY[MUTABLE_BIG_INTEGER] 51 -- Give another independant copy of `numbers_check'. 52 local 53 i: INTEGER 54 once 55 create Result.with_capacity(numbers_check.capacity) 56 from 57 i := numbers_check.lower 58 until 59 i > numbers_check.upper 60 loop 61 Result.add_last(numbers_check.item(i).twin) 62 end 63 end 64 65 restore (n: FAST_ARRAY[MUTABLE_BIG_INTEGER]) 66 -- Restore `n' (which is `number1' or `number2'. 67 require 68 n = numbers1 or n = numbers2 69 local 70 i: INTEGER 71 do 72 from 73 i := numbers_check.lower 74 until 75 i > numbers_check.upper 76 loop 77 if numbers_check.item(i).is_equal(n.item(i)) then 78 if n.item(i) = Void then 79 n.put(numbers_check.item(i).twin, i) 80 else 81 n.item(i).copy(numbers_check.item(i)) 82 end 83 end 84 i := i + 1 85 end 86 end 87 88 verify (n: FAST_ARRAY[MUTABLE_BIG_INTEGER]) 89 -- Are the numbers original ? Restore the bad number. 90 local 91 i: INTEGER 92 do 93 from 94 i := numbers_check.lower 95 until 96 i > numbers_check.upper 97 loop 98 assert(numbers_check.item(i).is_equal(n.item(i))) 99 i := i + 1 100 end 101 end 102 103 verify_and_restore (n: FAST_ARRAY[MUTABLE_BIG_INTEGER]) 104 -- Are the numbers original ? Restore the bad number. 105 local 106 i: INTEGER; b: BOOLEAN 107 do 108 from 109 i := numbers_check.lower 110 until 111 i > numbers_check.upper 112 loop 113 b := numbers_check.item(i).is_equal(n.item(i)) 114 assert(b) 115 if b then 116 if n.item(i) = Void then 117 n.put(numbers_check.item(i).twin, i) 118 else 119 n.item(i).copy(numbers_check.item(i)) 120 end 121 end 122 i := i + 1 123 end 124 end 125 126end -- class AUX_MUTABLE_BIG_INTEGER1 127-- 128-- ------------------------------------------------------------------------------------------------------------------------------ 129-- Copyright notice below. Please read. 130-- 131-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, 132-- as published by the Free Software Foundation; either version 2, or (at your option) any later version. 133-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty 134-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have 135-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free 136-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 137-- 138-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE 139-- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE 140-- 141-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN 142-- 143-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr 144-- ------------------------------------------------------------------------------------------------------------------------------