/test/lib/numeric/real/test_real_constant05.e

http://github.com/tybor/Liberty · Specman e · 79 lines · 46 code · 4 blank · 29 comment · 0 complexity · 8a6c53532ca8fa640d21a7a494ac71ba 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. --
  4. class TEST_REAL_CONSTANT05
  5. --
  6. -- Various notation for REAL_*
  7. --
  8. insert
  9. EIFFELTEST_TOOLS
  10. create {}
  11. make
  12. feature {ANY}
  13. make
  14. local
  15. real_32: REAL_32; real_64: REAL_64; real: REAL; real_extended: REAL_EXTENDED; string: STRING
  16. do
  17. -- Testing REAL / REAL_64:
  18. assert(0.0 < 0.1)
  19. real := 10.0
  20. assert(real.to_string.is_equal("10.000000"))
  21. assert(real.to_string_format(1).is_equal("10.0"))
  22. real_64 := 1.0E1
  23. assert(real_64.to_string.is_equal("10.000000"))
  24. assert(real_64.to_string_format(0).is_equal("10"))
  25. assert(real = real_64)
  26. assert(10.0 = 1.0e1)
  27. -- Testing REAL_32:
  28. real_32 := {REAL_32 0.0}
  29. assert(real_32.to_string.is_equal("0.000000"))
  30. assert(real_32.to_string_format(8).is_equal("0.00000000"))
  31. assert(real_32 = 0.0)
  32. real_32 := {REAL_32 0.5}
  33. assert(real_32.to_string.is_equal("0.500000"))
  34. assert(real_32.to_string_format(1).is_equal("0.5"))
  35. assert(real_32 = 0.5)
  36. -- Testing REAL_EXTENDED:
  37. real_extended := {REAL_EXTENDED 3.5}
  38. assert(real_extended = 3.5)
  39. assert(real_extended.to_string.is_equal("3.500000"))
  40. assert(real_extended.to_string_format(6).is_equal("3.500000"))
  41. real_extended := 3.5
  42. assert(real_extended = {REAL_EXTENDED 35E-1})
  43. real_extended := 3.888
  44. assert(real_extended.to_string.is_equal("3.888000"))
  45. assert(real_extended.to_string_format(3).is_equal("3.888"))
  46. -- Finally, testing assignments:
  47. real_32 := {REAL_32 0.1}
  48. real_64 := real_32
  49. assert(real_64.to_string.is_equal("0.100000"))
  50. real_extended := real_64
  51. string := 155.5.to_string_scientific(4)
  52. assert(155.5.to_string_scientific(4).is_equal("1.5550e+02"))
  53. -- Testing manifest notation with '_' for reals
  54. real_64 := 5_000.0
  55. assert((real_64 - 5000.0).abs < 0.1)
  56. end
  57. end -- class TEST_REAL_CONSTANT05
  58. --
  59. -- ------------------------------------------------------------------------------------------------------------------------------
  60. -- Copyright notice below. Please read.
  61. --
  62. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  63. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  64. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  65. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  66. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  67. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  68. --
  69. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  70. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  71. --
  72. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  73. --
  74. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  75. -- ------------------------------------------------------------------------------------------------------------------------------