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

/test/lib/numeric/real/test_force_to_integer.e

http://github.com/tybor/Liberty
Specman e | 85 lines | 59 code | 4 blank | 22 comment | 0 complexity | 34585038e2df695f9ee4b734e9ad1d5f 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_FORCE_TO_INTEGER
 5   -- To test force_to_integer_64, force_to_integer_32 and force_to_integer_16.
 6
 7insert
 8   EIFFELTEST_TOOLS
 9
10create {}
11   make
12
13feature {ANY}
14   make
15      local
16         integer_16: INTEGER_16; integer_32: INTEGER_32; integer_64: INTEGER_64; real_32: REAL_32; real_64: REAL_64
17      do
18         real_64 := 0.4
19         integer_16 := real_64.force_to_integer_16
20         assert(integer_16 = 0)
21         assert(0.4.force_to_integer_16 = 0)
22         real_32 := {REAL_32 0.4}
23         integer_16 := real_32.force_to_integer_16
24         assert(integer_16 = 0)
25         assert({REAL_32 0.4}.force_to_integer_16 = 0)
26         real_64 := 0.4
27         integer_32 := real_64.force_to_integer_32
28         assert(integer_32 = 0)
29         assert(0.4.force_to_integer_32 = 0)
30         real_32 := {REAL_32 0.4}
31         integer_32 := real_32.force_to_integer_32
32         assert(integer_32 = 0)
33         assert({REAL_32 0.4}.force_to_integer_32 = 0)
34         real_64 := 0.4
35         integer_64 := real_64.force_to_integer_64
36         assert(integer_64 = 0)
37         assert(0.4.force_to_integer_64 = 0)
38         real_32 := {REAL_32 0.4}
39         integer_64 := real_32.force_to_integer_64
40         assert(integer_64 = 0)
41         assert({REAL_32 0.4}.force_to_integer_64 = 0)
42         assert(0.51.force_to_integer_64 = 0)
43         assert(0.51.force_to_integer_32 = 0)
44         assert(0.51.force_to_integer_16 = 0)
45         assert(1.49.force_to_integer_64 = 1)
46         assert(1.49.force_to_integer_32 = 1)
47         assert(1.49.force_to_integer_16 = 1)
48         assert(1.51.force_to_integer_64 = 1)
49         assert(1.51.force_to_integer_32 = 1)
50         assert(1.51.force_to_integer_16 = 1)
51         assert((-0.4).rounded.force_to_integer_32 = 0)
52         assert((-0.51).rounded.force_to_integer_32 = -1)
53         assert((-1.49).ceiling.force_to_integer_32 = -1)
54         assert((-1.51).floor.force_to_integer_32 = -2)
55         integer_64 := -9007199254740992
56         assert(integer_64.fit_real_64)
57         real_64 := integer_64.force_to_real_64
58         assert(real_64.force_to_integer_64 = integer_64)
59         integer_64 := -9007199254740993
60         assert(not integer_64.fit_real_64)
61         integer_64 := -9007199254740994
62         assert(integer_64.fit_real_64)
63         real_64 := integer_64.force_to_real_64
64         assert(real_64.force_to_integer_64 = integer_64)
65      end
66
67end -- class TEST_FORCE_TO_INTEGER
68--
69-- ------------------------------------------------------------------------------------------------------------------------------
70-- Copyright notice below. Please read.
71--
72-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
73-- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
74-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
75-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
76-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
77-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
78--
79-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P.       - University of Nancy 1 - FRANCE
80-- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
81--
82-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
83--
84-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
85-- ------------------------------------------------------------------------------------------------------------------------------