tint.pp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. { this tests the int routine }
  2. { Contrary to TP, int can be used in the constant section,
  3. just like in Delphi }
  4. program tint;
  5. {$ifdef VER1_0}
  6. {$define SKIP_CURRENCY_TEST}
  7. {$endif }
  8. const
  9. INT_RESULT_ONE = 1234;
  10. INT_VALUE_ONE = 1234.5678;
  11. INT_RESULT_CONST_ONE = Int(INT_VALUE_ONE);
  12. INT_RESULT_TWO = -1234;
  13. INT_VALUE_TWO = -1234.5678;
  14. INT_RESULT_CONST_TWO = Int(INT_VALUE_TWO);
  15. procedure fail;
  16. begin
  17. WriteLn('Failed!');
  18. halt(1);
  19. end;
  20. procedure test_int_real;
  21. var
  22. r: real;
  23. _success : boolean;
  24. Begin
  25. Write('Int() real testing...');
  26. _success := true;
  27. r:=INT_VALUE_ONE;
  28. if Int(r)<>INT_RESULT_ONE then
  29. _success:=false;
  30. if Int(INT_VALUE_ONE)<>INT_RESULT_ONE then
  31. _success:=false;
  32. r:=INT_VALUE_ONE;
  33. if Int(r)<>INT_RESULT_CONST_ONE then
  34. _success := false;
  35. r:=INT_VALUE_ONE;
  36. r:=Int(r);
  37. if r<>INT_RESULT_ONE then
  38. _success:=false;
  39. r:=Int(INT_VALUE_ONE);
  40. if r<>INT_RESULT_ONE then
  41. _success:=false;
  42. r:=INT_VALUE_TWO;
  43. if Int(r)<>INT_RESULT_TWO then
  44. _success:=false;
  45. if Int(INT_VALUE_TWO)<>INT_RESULT_TWO then
  46. _success:=false;
  47. r:=INT_VALUE_TWO;
  48. if Int(r)<>INT_RESULT_CONST_TWO then
  49. _success := false;
  50. r:=INT_VALUE_TWO;
  51. r:=Int(r);
  52. if r<>INT_RESULT_TWO then
  53. _success:=false;
  54. r:=Int(INT_VALUE_TWO);
  55. if r<>INT_RESULT_TWO then
  56. _success:=false;
  57. if not _success then
  58. fail;
  59. WriteLn('Success!');
  60. end;
  61. procedure test_int_single;
  62. var
  63. r: single;
  64. _success : boolean;
  65. Begin
  66. Write('Int() single testing...');
  67. _success := true;
  68. r:=INT_VALUE_ONE;
  69. if Int(r)<>INT_RESULT_ONE then
  70. _success:=false;
  71. if Int(INT_VALUE_ONE)<>INT_RESULT_ONE then
  72. _success:=false;
  73. r:=INT_VALUE_ONE;
  74. if Int(r)<>INT_RESULT_CONST_ONE then
  75. _success := false;
  76. r:=INT_VALUE_ONE;
  77. r:=Int(r);
  78. if r<>INT_RESULT_ONE then
  79. _success:=false;
  80. r:=Int(INT_VALUE_ONE);
  81. if r<>INT_RESULT_ONE then
  82. _success:=false;
  83. r:=INT_VALUE_TWO;
  84. if Int(r)<>INT_RESULT_TWO then
  85. _success:=false;
  86. if Int(INT_VALUE_TWO)<>INT_RESULT_TWO then
  87. _success:=false;
  88. r:=INT_VALUE_TWO;
  89. if Int(r)<>INT_RESULT_CONST_TWO then
  90. _success := false;
  91. r:=INT_VALUE_TWO;
  92. r:=Int(r);
  93. if r<>INT_RESULT_TWO then
  94. _success:=false;
  95. r:=Int(INT_VALUE_TWO);
  96. if r<>INT_RESULT_TWO then
  97. _success:=false;
  98. if not _success then
  99. fail;
  100. WriteLn('Success!');
  101. end;
  102. procedure test_int_double;
  103. var
  104. r: double;
  105. _success : boolean;
  106. Begin
  107. Write('Int() double testing...');
  108. _success := true;
  109. r:=INT_VALUE_ONE;
  110. if Int(r)<>INT_RESULT_ONE then
  111. _success:=false;
  112. if Int(INT_VALUE_ONE)<>INT_RESULT_ONE then
  113. _success:=false;
  114. r:=INT_VALUE_ONE;
  115. if Int(r)<>INT_RESULT_CONST_ONE then
  116. _success := false;
  117. r:=INT_VALUE_ONE;
  118. r:=Int(r);
  119. if r<>INT_RESULT_ONE then
  120. _success:=false;
  121. r:=Int(INT_VALUE_ONE);
  122. if r<>INT_RESULT_ONE then
  123. _success:=false;
  124. r:=INT_VALUE_TWO;
  125. if Int(r)<>INT_RESULT_TWO then
  126. _success:=false;
  127. if Int(INT_VALUE_TWO)<>INT_RESULT_TWO then
  128. _success:=false;
  129. r:=INT_VALUE_TWO;
  130. if Int(r)<>INT_RESULT_CONST_TWO then
  131. _success := false;
  132. r:=INT_VALUE_TWO;
  133. r:=Int(r);
  134. if r<>INT_RESULT_TWO then
  135. _success:=false;
  136. r:=Int(INT_VALUE_TWO);
  137. if r<>INT_RESULT_TWO then
  138. _success:=false;
  139. if not _success then
  140. fail;
  141. WriteLn('Success!');
  142. end;
  143. {$ifndef SKIP_CURRENCY_TEST}
  144. procedure test_int_currency;
  145. var
  146. r: currency;
  147. _success : boolean;
  148. Begin
  149. Write('Int() currency testing...');
  150. _success := true;
  151. r:=INT_VALUE_ONE;
  152. if Int(r)<>INT_RESULT_ONE then
  153. _success:=false;
  154. if not _success then
  155. fail;
  156. if Int(INT_VALUE_ONE)<>INT_RESULT_ONE then
  157. _success:=false;
  158. r:=INT_VALUE_ONE;
  159. if Int(r)<>INT_RESULT_CONST_ONE then
  160. _success := false;
  161. r:=INT_VALUE_ONE;
  162. r:=Int(r);
  163. if r<>INT_RESULT_ONE then
  164. _success:=false;
  165. r:=Int(INT_VALUE_ONE);
  166. if r<>INT_RESULT_ONE then
  167. _success:=false;
  168. if not _success then
  169. fail;
  170. r:=INT_VALUE_TWO;
  171. if Int(r)<>INT_RESULT_TWO then
  172. _success:=false;
  173. if Int(INT_VALUE_TWO)<>INT_RESULT_TWO then
  174. _success:=false;
  175. r:=INT_VALUE_TWO;
  176. if Int(r)<>INT_RESULT_CONST_TWO then
  177. _success := false;
  178. r:=INT_VALUE_TWO;
  179. r:=Int(r);
  180. if r<>INT_RESULT_TWO then
  181. _success:=false;
  182. r:=Int(INT_VALUE_TWO);
  183. if r<>INT_RESULT_TWO then
  184. _success:=false;
  185. if not _success then
  186. fail;
  187. WriteLn('Success!');
  188. end;
  189. {$endif SKIP_CURRENCY_TEST}
  190. Begin
  191. test_int_real;
  192. test_int_double;
  193. test_int_single;
  194. {$ifdef SKIP_CURRENCY_TEST}
  195. Writeln('Skipping currency test because its not supported by theis compiler');
  196. {$else SKIP_CURRENCY_TEST}
  197. test_int_currency;
  198. {$endif SKIP_CURRENCY_TEST}
  199. end.