/test/lib/numeric/integer/test_to_hexadecimal.e

http://github.com/tybor/Liberty · Specman e · 156 lines · 127 code · 5 blank · 24 comment · 1 complexity · 102a0c6830e0e20a16e0306a55872027 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_TO_HEXADECIMAL
  5. create {}
  6. make
  7. feature {ANY}
  8. make
  9. local
  10. i8: INTEGER_8; i16: INTEGER_16; i32: INTEGER_32; i64: INTEGER_64; view: STRING
  11. do
  12. i8 := 0
  13. assert(i8.hexadecimal_digit = '0')
  14. assert(0.hexadecimal_digit = '0')
  15. i8 := 1
  16. assert(i8.hexadecimal_digit = '1')
  17. assert(1.hexadecimal_digit = '1')
  18. i8 := 8
  19. assert(i8.hexadecimal_digit = '8')
  20. assert(8.hexadecimal_digit = '8')
  21. i8 := 9
  22. assert(i8.hexadecimal_digit = '9')
  23. assert(9.hexadecimal_digit = '9')
  24. i8 := 10
  25. assert(i8.hexadecimal_digit = 'A')
  26. assert(10.hexadecimal_digit = 'A')
  27. i8 := 15
  28. assert(i8.hexadecimal_digit = 'F')
  29. assert(15.hexadecimal_digit = 'F')
  30. -- -------------------------------------
  31. i8 := -128
  32. view := i8.to_hexadecimal
  33. assert(("80").is_equal(view))
  34. i8 := -127
  35. view := i8.to_hexadecimal
  36. assert(("81").is_equal(view))
  37. i8 := -2
  38. view := i8.to_hexadecimal
  39. assert(("FE").is_equal(view))
  40. i8 := -1
  41. view := i8.to_hexadecimal
  42. assert(("FF").is_equal(view))
  43. i8 := 0
  44. view := i8.to_hexadecimal
  45. assert(("00").is_equal(view))
  46. i8 := 1
  47. view := i8.to_hexadecimal
  48. assert(("01").is_equal(view))
  49. i8 := 2
  50. view := i8.to_hexadecimal
  51. assert(("02").is_equal(view))
  52. i8 := 126
  53. view := i8.to_hexadecimal
  54. assert(("7E").is_equal(view))
  55. i8 := 127
  56. view := i8.to_hexadecimal
  57. assert(("7F").is_equal(view))
  58. -- -------------------------------------
  59. i16 := -32768
  60. view := i16.to_hexadecimal
  61. assert(("8000").is_equal(view))
  62. i16 := -32767
  63. view := i16.to_hexadecimal
  64. assert(("8001").is_equal(view))
  65. i16 := -2
  66. view := i16.to_hexadecimal
  67. assert(("FFFE").is_equal(view))
  68. i16 := -1
  69. view := i16.to_hexadecimal
  70. assert(("FFFF").is_equal(view))
  71. i16 := 0
  72. view := i16.to_hexadecimal
  73. assert(("0000").is_equal(view))
  74. i16 := 1
  75. view := i16.to_hexadecimal
  76. assert(("0001").is_equal(view))
  77. i16 := 2
  78. view := i16.to_hexadecimal
  79. assert(("0002").is_equal(view))
  80. i16 := 32767
  81. view := i16.to_hexadecimal
  82. assert(("7FFF").is_equal(view))
  83. i16 := 32766
  84. view := i16.to_hexadecimal
  85. assert(("7FFE").is_equal(view))
  86. i32 := -2147483648
  87. view := i32.to_hexadecimal
  88. assert(("80000000").is_equal(view))
  89. i32 := -2147483647
  90. view := i32.to_hexadecimal
  91. assert(("80000001").is_equal(view))
  92. i32 := -2
  93. view := i32.to_hexadecimal
  94. assert(("FFFFFFFE").is_equal(view))
  95. i32 := -1
  96. view := i32.to_hexadecimal
  97. assert(("FFFFFFFF").is_equal(view))
  98. i32 := 0
  99. view := i32.to_hexadecimal
  100. assert(("00000000").is_equal(view))
  101. i32 := 1
  102. view := i32.to_hexadecimal
  103. assert(("00000001").is_equal(view))
  104. i32 := 2
  105. view := i32.to_hexadecimal
  106. assert(("00000002").is_equal(view))
  107. i32 := 2147483646
  108. view := i32.to_hexadecimal
  109. assert(("7FFFFFFE").is_equal(view))
  110. i32 := 2147483647
  111. view := i32.to_hexadecimal
  112. assert(("7FFFFFFF").is_equal(view))
  113. -- -------------------------------------
  114. i64 := -2147483649
  115. view := i64.to_hexadecimal
  116. assert(("FFFFFFFF7FFFFFFF").is_equal(view))
  117. i64 := 2147483648
  118. view := i64.to_hexadecimal
  119. assert(("0000000080000000").is_equal(view))
  120. end
  121. assert (b: BOOLEAN)
  122. do
  123. cpt := cpt + 1
  124. if not b then
  125. sedb_breakpoint
  126. std_output.put_string("TEST_TO_HEXADECIMAL: ERROR Test # ")
  127. std_output.put_integer(cpt)
  128. std_output.put_string("%N")
  129. crash
  130. end
  131. end
  132. cpt: INTEGER
  133. end -- class TEST_TO_HEXADECIMAL
  134. --
  135. -- ------------------------------------------------------------------------------------------------------------------------------
  136. -- Copyright notice below. Please read.
  137. --
  138. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  139. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  140. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  141. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  142. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  143. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  144. --
  145. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  146. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  147. --
  148. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  149. --
  150. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  151. -- ------------------------------------------------------------------------------------------------------------------------------