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

/test/lib/numeric/mutable_big_integer/test_mutable_big_integer7bis.e

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