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