PageRenderTime 13ms CodeModel.GetById 3ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/test/lib/numeric/integer/test_integer1.e

http://github.com/tybor/Liberty
Specman e | 372 lines | 340 code | 6 blank | 26 comment | 1 complexity | 7657cbb23991ad97167f47a4f0a963c6 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_INTEGER1
  5
  6insert
  7   ANY
  8   PLATFORM
  9
 10create {}
 11   make
 12
 13feature {ANY}
 14   make
 15      local
 16         tmp_string: STRING; i: INTEGER
 17      do
 18         assert(1 = 1)
 19         assert(0 = 0)
 20         assert(-1 = -1)
 21         assert(0 + 1 = 1)
 22         assert(1 = 1 + 0)
 23         assert(0 - 1 = -1)
 24         assert(-1 = -1 + 0)
 25         assert(2 + 2 = 4)
 26         assert(2 + 2 /= 3)
 27         assert(2 * 2 = 4)
 28         assert(4 = 2 * 2)
 29         i := 76
 30         assert(76 = i)
 31         assert(i + 1 = 77)
 32         assert(76 = i)
 33         i := 0
 34         assert(i // 1 = 0)
 35         assert(i \\ 1 = 0)
 36         assert(i // -1 = 0)
 37         assert(i \\ -1 = 0)
 38         assert(i // 10 = 0)
 39         assert(i \\ 10 = 0)
 40         assert(i // -10 = 0)
 41         assert(i \\ -10 = 0)
 42         assert(i // Minimum_integer = 0)
 43         assert(i \\ Minimum_integer = 0)
 44         assert(i // Maximum_integer = 0)
 45         assert(i \\ Maximum_integer = 0)
 46         assert(i // (Minimum_integer + 10) = 0)
 47         assert(i \\ (Minimum_integer + 10) = 0)
 48         assert(i // (Maximum_integer - 10) = 0)
 49         assert(i \\ (Maximum_integer - 10) = 0)
 50         assert(i = 0)
 51         i := 1
 52         assert(i // 1 = 1)
 53         assert(i \\ 1 = 0)
 54         assert(i // -1 = -1)
 55         assert(i \\ -1 = 0)
 56         assert(i // 10 = 0)
 57         assert(i \\ 10 = 1)
 58         assert(i // -10 = 0)
 59         assert(i \\ -10 = 1)
 60         assert(i // Minimum_integer = 0)
 61         assert(i \\ Minimum_integer = 1)
 62         assert(i // Maximum_integer = 0)
 63         assert(i \\ Maximum_integer = 1)
 64         assert(i // (Minimum_integer + 10) = 0)
 65         assert(i \\ (Minimum_integer + 10) = 1)
 66         assert(i // (Maximum_integer - 10) = 0)
 67         assert(i \\ (Maximum_integer - 10) = 1)
 68         assert(i = 1)
 69         i := -1
 70         assert(i // 1 = -1)
 71         assert(i \\ 1 = 0)
 72         assert(i // -1 = 1)
 73         assert(i \\ -1 = 0)
 74         assert(i // 10 = -1)
 75         assert(i \\ 10 = 9)
 76         assert(i // -10 = 1)
 77         assert(i \\ -10 = 9)
 78         assert(i // Minimum_integer_32 = 1)
 79         assert(i \\ Minimum_integer = Maximum_integer)
 80         assert(i // Maximum_integer = -1)
 81         assert(i \\ Maximum_integer = Maximum_integer - 1)
 82         assert(i // (Minimum_integer + 10) = 1)
 83         assert(i \\ (Minimum_integer + 10) = Maximum_integer - 10)
 84         assert(i // (Maximum_integer - 10) = -1)
 85         assert(i \\ (Maximum_integer - 10) = Maximum_integer - 11)
 86         assert(i = -1)
 87         i := 10
 88         assert(i // 1 = 10)
 89         assert(i \\ 1 = 0)
 90         assert(i // -1 = -10)
 91         assert(i \\ -1 = 0)
 92         assert(i // 10 = 1)
 93         assert(i \\ 10 = 0)
 94         assert(i // -10 = -1)
 95         assert(i \\ -10 = 0)
 96         assert(i // Minimum_integer = 0)
 97         assert(i \\ Minimum_integer = 10)
 98         assert(i // Maximum_integer = 0)
 99         assert(i \\ Maximum_integer = 10)
100         assert(i // (Minimum_integer + 10) = 0)
101         assert(i \\ (Minimum_integer + 10) = 10)
102         assert(i // (Maximum_integer - 10) = 0)
103         assert(i \\ (Maximum_integer - 10) = 10)
104         assert(i = 10)
105         i := -10
106         assert(i // 1 = -10)
107         assert(i \\ 1 = 0)
108         assert(i // -1 = 10)
109         assert(i \\ -1 = 0)
110         assert(i // 10 = -1)
111         assert(i \\ 10 = 0)
112         assert(i // -10 = 1)
113         assert(i \\ -10 = 0)
114         assert(i // Minimum_integer = 1)
115         assert(i \\ Minimum_integer = Maximum_integer - 9)
116         assert(i // Maximum_integer = -1)
117         assert(i \\ Maximum_integer = Maximum_integer - 10)
118         assert(i // (Minimum_integer + 10) = 1)
119         assert(i \\ (Minimum_integer + 10) = Maximum_integer - 19)
120         assert(i // (Maximum_integer - 10) = -1)
121         assert(i \\ (Maximum_integer - 10) = Maximum_integer - 20)
122         assert(i = -10)
123         i := 30
124         assert(i // 1 = 30)
125         assert(i \\ 1 = 0)
126         assert(i // -1 = -30)
127         assert(i \\ -1 = 0)
128         assert(i // 10 = 3)
129         assert(i \\ 10 = 0)
130         assert(i // -10 = -3)
131         assert(i \\ -10 = 0)
132         assert(i // Minimum_integer = 0)
133         assert(i \\ Minimum_integer = 30)
134         assert(i // Maximum_integer = 0)
135         assert(i \\ Maximum_integer = 30)
136         assert(i // (Minimum_integer + 10) = 0)
137         assert(i \\ (Minimum_integer + 10) = 30)
138         assert(i // (Maximum_integer - 10) = 0)
139         assert(i \\ (Maximum_integer - 10) = 30)
140         assert(i = 30)
141         i := -30
142         assert(i // 1 = -30)
143         assert(i \\ 1 = 0)
144         assert(i // -1 = 30)
145         assert(i \\ -1 = 0)
146         assert(i // 10 = -3)
147         assert(i \\ 10 = 0)
148         assert(i // -10 = 3)
149         assert(i \\ -10 = 0)
150         assert(i // Minimum_integer = 1)
151         assert(i \\ Minimum_integer = Maximum_integer - 29)
152         assert(i // Maximum_integer = -1)
153         assert(i \\ Maximum_integer = Maximum_integer - 30)
154         assert(i // (Minimum_integer + 10) = 1)
155         assert(i \\ (Minimum_integer + 10) = Maximum_integer - 39)
156         assert(i // (Maximum_integer - 10) = -1)
157         assert(i \\ (Maximum_integer - 10) = Maximum_integer - 40)
158         assert(i = -30)
159         i := 31
160         assert(i // 1 = 31)
161         assert(i \\ 1 = 0)
162         assert(i // -1 = -31)
163         assert(i \\ -1 = 0)
164         assert(i // 10 = 3)
165         assert(i \\ 10 = 1)
166         assert(i // -10 = -3)
167         assert(i \\ -10 = 1)
168         assert(i // Minimum_integer = 0)
169         assert(i \\ Minimum_integer = 31)
170         assert(i // Maximum_integer = 0)
171         assert(i \\ Maximum_integer = 31)
172         assert(i // (Minimum_integer + 10) = 0)
173         assert(i \\ (Minimum_integer + 10) = 31)
174         assert(i // (Maximum_integer - 10) = 0)
175         assert(i \\ (Maximum_integer - 10) = 31)
176         assert(i = 31)
177         i := -31
178         assert(i // 1 = -31)
179         assert(i \\ 1 = 0)
180         assert(i // -1 = 31)
181         assert(i \\ -1 = 0)
182         assert(i // 10 = -4)
183         assert(i \\ 10 = 9)
184         assert(i // -10 = 4)
185         assert(i \\ -10 = 9)
186         assert(i // Minimum_integer = 1)
187         assert(i \\ Minimum_integer = Maximum_integer - 30)
188         assert(i // Maximum_integer = -1)
189         assert(i \\ Maximum_integer = Maximum_integer - 31)
190         assert(i // (Minimum_integer + 10) = 1)
191         assert(i \\ (Minimum_integer + 10) = Maximum_integer - 40)
192         assert(i // (Maximum_integer - 10) = -1)
193         assert(i \\ (Maximum_integer - 10) = Maximum_integer - 41)
194         assert(i = -31)
195         i := 29
196         assert(i // 1 = 29)
197         assert(i \\ 1 = 0)
198         assert(i // -1 = -29)
199         assert(i \\ -1 = 0)
200         assert(i // 10 = 2)
201         assert(i \\ 10 = 9)
202         assert(i // -10 = -2)
203         assert(i \\ -10 = 9)
204         assert(i // Minimum_integer = 0)
205         assert(i \\ Minimum_integer = 29)
206         assert(i // Maximum_integer = 0)
207         assert(i \\ Maximum_integer = 29)
208         assert(i // (Minimum_integer + 10) = 0)
209         assert(i \\ (Minimum_integer + 10) = 29)
210         assert(i // (Maximum_integer - 10) = 0)
211         assert(i \\ (Maximum_integer - 10) = 29)
212         assert(i = 29)
213         i := -29
214         assert(i // 1 = -29)
215         assert(i \\ 1 = 0)
216         assert(i // -1 = 29)
217         assert(i \\ -1 = 0)
218         assert(i // 10 = -3)
219         assert(i \\ 10 = 1)
220         assert(i // -10 = 3)
221         assert(i \\ -10 = 1)
222         assert(i // Minimum_integer = 1)
223         assert(i \\ Minimum_integer = Maximum_integer - 28)
224         assert(i // Maximum_integer = -1)
225         assert(i \\ Maximum_integer = Maximum_integer - 29)
226         assert(i // (Minimum_integer + 10) = 1)
227         assert(i \\ (Minimum_integer + 10) = Maximum_integer - 38)
228         assert(i // (Maximum_integer - 10) = -1)
229         assert(i \\ (Maximum_integer - 10) = Maximum_integer - 39)
230         assert(i = -29)
231         i := Maximum_integer
232         assert(i // 1 = Maximum_integer)
233         assert(i \\ 1 = 0)
234         assert(i // -1 = -Maximum_integer)
235         assert(i \\ -1 = 0)
236         assert(i // 10 = 214748364)
237         assert(i \\ 10 = 7)
238         assert(i // -10 = -214748364)
239         assert(i \\ -10 = 7)
240         assert(i // Minimum_integer = 0)
241         assert(i \\ Minimum_integer = Maximum_integer)
242         assert(i // Maximum_integer = 1)
243         assert(i \\ Maximum_integer = 0)
244         assert(i // (Minimum_integer + 10) = -1)
245         assert(i \\ (Minimum_integer + 10) = 9)
246         assert(i // (Maximum_integer - 10) = 1)
247         assert(i \\ (Maximum_integer - 10) = 10)
248         assert(i = Maximum_integer)
249         i := Minimum_integer
250         assert(i // 1 = Minimum_integer)
251         assert(i \\ 1 = 0)
252         --    assert(i // -1 = -Minimum_integer)       overflow !!
253         -- *** C ANSI 99 BUG !!! (i #\\ -1) give an overflow !!!
254         -- (Vincent Croizier, 02/11/2004) ***
255         --         assert(i \\ -1 = 0)
256         assert(i // 10 = -214748365)
257         assert(i \\ 10 = 2)
258         assert(i // -10 = 214748365)
259         assert(i \\ -10 = 2)
260         assert(i // Minimum_integer = 1)
261         assert(i \\ Minimum_integer = 0)
262         assert(i // Maximum_integer = -2)
263         assert(i \\ Maximum_integer = Maximum_integer - 1)
264         assert(i // (Minimum_integer + 10) = 2)
265         assert(i \\ (Minimum_integer + 10) = Maximum_integer - 19)
266         assert(i // (Maximum_integer - 10) = -2)
267         assert(i \\ (Maximum_integer - 10) = Maximum_integer - 21)
268         assert(i = Minimum_integer)
269         assert(2 ^ 0 = 1)
270         assert(2 ^ 1 = 2)
271         assert(2 ^ 2 = 4)
272         assert(2 ^ 3 = 8)
273         assert(3 ^ 0 = 1)
274         assert(3 ^ 1 = 3)
275         assert(3 ^ 2 = 9)
276         assert(3 ^ 3 = 27)
277         assert(-3 < -1)
278         assert(-1 < 0)
279         assert(-1 < 1)
280         assert(0 < 1)
281         assert(1 < 2)
282         assert(-3 <= -1)
283         assert(-3 <= -3)
284         assert(-1 <= 0)
285         assert(-1 <= 1)
286         assert(-1 <= -1)
287         assert(0 <= 1)
288         assert(1 <= 2)
289         assert(2 <= 2)
290         assert(not (3 <= 2))
291         assert(3 = 3)
292         assert(3 = +(1 + 2))
293         assert(-3 = 3 - 6)
294         assert(("0").is_equal(0.to_string))
295         assert(("25").is_equal(25.to_string))
296         assert(("-25").is_equal((-25).to_string))
297         assert((" 25").is_equal(25.to_string_format(3)))
298         assert((" -25").is_equal((-25).to_string_format(4)))
299         assert('0' = 0.digit)
300         assert('5' = 5.digit)
301         assert('9' = 9.digit)
302         assert(' ' = 32.to_character)
303         assert((-25).abs = 25)
304         assert(25.abs = 25)
305         assert(3.max(4) = 4)
306         assert(4.max(3) = 4)
307         assert(3.min(4) = 3)
308         assert(4.min(3) = 3)
309         assert((-2).min(2) = -2)
310         assert(2.max(-2) = 2)
311         -- testing to_octal_in
312         tmp_string := ""
313         0.to_octal_in(tmp_string)
314         assert(tmp_string.is_equal("000"))
315         tmp_string.clear_count
316         7.to_octal_in(tmp_string)
317         assert(tmp_string.is_equal("007"))
318         tmp_string.clear_count
319         8.to_octal_in(tmp_string)
320         assert(tmp_string.is_equal("010"))
321         tmp_string.clear_count
322         9.to_octal_in(tmp_string)
323         assert(tmp_string.is_equal("011"))
324         tmp_string.clear_count
325         ;(-10).to_octal_in(tmp_string)
326         assert(tmp_string.is_equal("366"))
327         tmp_string.clear_count
328         400.to_octal_in(tmp_string)
329         assert(tmp_string.is_equal("000620"))
330         tmp_string.clear_count
331         ;(-400).to_octal_in(tmp_string)
332         assert(tmp_string.is_equal("177160"))
333         tmp_string.clear_count
334         255.to_octal_in(tmp_string)
335         assert(tmp_string.is_equal("000377"))
336         tmp_string.clear_count
337         127.to_octal_in(tmp_string)
338         assert(tmp_string.is_equal("177"))
339      end
340
341   assert (b: BOOLEAN)
342      do
343         cpt := cpt + 1
344         if not b then
345            sedb_breakpoint
346            std_output.put_string("TEST_INTEGER1: ERROR Test # ")
347            std_output.put_integer(cpt)
348            std_output.put_string("%N")
349         end
350      end
351
352   cpt: INTEGER
353
354end -- class TEST_INTEGER1
355--
356-- ------------------------------------------------------------------------------------------------------------------------------
357-- Copyright notice below. Please read.
358--
359-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
360-- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
361-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
362-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
363-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
364-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
365--
366-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P.       - University of Nancy 1 - FRANCE
367-- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
368--
369-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
370--
371-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
372-- ------------------------------------------------------------------------------------------------------------------------------