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

/test/lib/numeric/test_clamp.e

http://github.com/tybor/Liberty
Specman e | 71 lines | 44 code | 12 blank | 15 comment | 0 complexity | bbb78454c7adecfce435778811ff41dd MD5 | raw file
 1-- This file is part of Liberty Eiffel Libraries.
 2-- See the Copyright notice at the end of this file.
 3
 4class TEST_CLAMP
 5   -- Testing COMPARABLE.bounded_by
 6   -- The feature bounded_by is called clamp in other languages.
 7
 8insert EIFFELTEST_TOOLS
 9
10create {}
11   make
12
13feature {ANY}
14   make
15      local
16         a,b,c: INTEGER_8; d,e,f: INTEGER_16
17      do
18         assert((10).bounded_by(5,20) = 10)
19         assert(( 2).bounded_by(5,20) =  5)
20         assert((-2).bounded_by(5,20) =  5)
21         assert((22).bounded_by(5,20) = 20)
22
23         assert((3/4).bounded_by(2/3, 4/5) =  3/4)
24         assert((2/3).bounded_by(3/4, 4/5) =  3/4)
25         assert((4/5).bounded_by(2/3, 3/4) =  3/4)
26
27         a := 5; b:= 10; c:= 20
28         assert( a.bounded_by(b,c) = b)
29         assert( b.bounded_by(a,c) = b)
30         assert( c.bounded_by(a,b) = b)
31
32         d:= 1005; e:= 1010; f:= 1020
33         assert( d.bounded_by(e,f) = e)
34         assert( e.bounded_by(d,f) = e)
35         assert( f.bounded_by(d,e) = e)
36
37         test_dates
38      end
39
40   test_dates
41      local
42         a,b,c,d: TIME
43      do
44         a.update; b.copy(a); c.copy(a)
45         b.add_hour(2)
46         c.add_day(1)
47
48         assert (a.bounded_by(b,c) ~ b)
49         assert (c.bounded_by(a,b) ~ b)
50         assert (b.bounded_by(a,c) ~ b)
51         d := a.bounded_by(b,c)
52         assert(d~b)
53         d := c.bounded_by(a,b)
54         assert (d ~ b)
55         d := b.bounded_by(a,c)
56         assert (b.bounded_by(a,c) ~ b)
57      end
58
59end -- class TEST_BOUNDED_BY
60
61-- ------------------------------------------------------------------------------------------------------------------------------
62-- Copyright notice below. Please read.
63--
64-- Liberty Eiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
65-- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
66-- Liberty Eiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
67-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
68-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
69-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
70--
71-- Copyright (C) 2011-2017: Paolo Redaelli