taddcurr.pp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. { %VERSION=1.1 }
  2. {****************************************************************}
  3. { CODE GENERATOR TEST PROGRAM }
  4. {****************************************************************}
  5. { NODE TESTED : secondadd() FPU currency type code }
  6. {****************************************************************}
  7. { PRE-REQUISITES: secondload() }
  8. { secondassign() }
  9. { secondtypeconv() }
  10. {****************************************************************}
  11. { DEFINES: }
  12. { FPC = Target is FreePascal compiler }
  13. {****************************************************************}
  14. { REMARKS: }
  15. { }
  16. { }
  17. { }
  18. {****************************************************************}
  19. { Result is either LOC_FPU or LOC_REFERENCE }
  20. { LEFT NODE (operand) (left operator) }
  21. { LOC_REFERENCE / LOC_MEM }
  22. { LOC_FPU }
  23. { RIGHT NODE (operand) }
  24. { LOC_FPU }
  25. { LOC_REFERENCE / LOC_MEM }
  26. procedure fail;
  27. begin
  28. WriteLn('Failed!');
  29. halt(1);
  30. end;
  31. Procedure CurrencyTestSub;
  32. var
  33. i : Currency;
  34. j : Currency;
  35. result : boolean;
  36. Begin
  37. Write('Currency - Currency test...');
  38. result := true;
  39. i:=99.9;
  40. j:=10.0;
  41. i:=i-j;
  42. if trunc(i) <> trunc(89.9) then
  43. result := false;
  44. WriteLn('Result (89.9) :',i);
  45. i:=j-i;
  46. if trunc(i) <> trunc(-79.9) then
  47. result := false;
  48. WriteLn('Result (-79.9) :',i);
  49. j:=j-10.0;
  50. if j <> 0.0 then
  51. result := false;
  52. WriteLn('Result (0.0) :',j);
  53. if not result then
  54. Fail
  55. else
  56. WriteLn('Success.');
  57. end;
  58. procedure CurrencyTestAdd;
  59. var
  60. i : Currency;
  61. j : Currency;
  62. result : boolean;
  63. Begin
  64. WriteLn('Currency + Currency test...');
  65. result := true;
  66. i:= 9;
  67. i:=i+1.5;
  68. if trunc(i) <> trunc(10.5) then
  69. result := false;
  70. WriteLn('Result (10.5) :',i);
  71. i := 0.0;
  72. j := 100.0;
  73. i := i + j + j + 12.5;
  74. if trunc(i) <> trunc(212.5) then
  75. result := false;
  76. WriteLn('Result (212.5) :',i);
  77. if not result then
  78. Fail
  79. else
  80. WriteLn('Success.');
  81. end;
  82. procedure CurrencyTestmul;
  83. var
  84. i : Currency;
  85. j : Currency;
  86. result : boolean;
  87. begin
  88. WriteLn('Currency * Currency test...');
  89. result := true;
  90. i:= 0;
  91. j:= 0;
  92. i := i * j * i;
  93. if trunc(i) <> trunc(0.0) then
  94. result := false;
  95. WriteLn('Result (0.0) :',i);
  96. i := 10.0;
  97. j := -12.0;
  98. i := i * j * 10.0;
  99. if trunc(i) <> trunc(-1200.0) then
  100. result := false;
  101. WriteLn('Result (-1200.0) :',i);
  102. if not result then
  103. Fail
  104. else
  105. WriteLn('Success.');
  106. end;
  107. Procedure CurrencyTestDiv;
  108. var
  109. i : Currency;
  110. j : Currency;
  111. result : boolean;
  112. Begin
  113. result := true;
  114. WriteLn('Currency / Currency test...');
  115. i:=-99.9;
  116. j:=10.0;
  117. i:=i / j;
  118. if trunc(i) <> trunc(-9.9) then
  119. result := false;
  120. WriteLn('Result (-9.9) :',i);
  121. i:=j / i;
  122. if trunc(i) <> trunc(-1.01) then
  123. result := false;
  124. WriteLN('Result (-1.01) :',i);
  125. j:=i / 10.0;
  126. if trunc(j) <> trunc(-0.1001) then
  127. result := false;
  128. WriteLn('Result (-0.1001) :',j);
  129. if not result then
  130. Fail
  131. else
  132. WriteLn('Success.');
  133. end;
  134. { Procedure CurrencyTestComplex;
  135. var
  136. i : real;
  137. Begin
  138. Write('RESULT SHOULD BE 2.09 :');
  139. i := 4.4;
  140. WriteLn(Sqrt(i));
  141. Write('RESULT SHOULD BE PI :');
  142. WriteLn(Pi);
  143. Write('RESULT SHOULD BE 4.0 :');
  144. WriteLn(Round(3.6));
  145. end;}
  146. procedure CurrencyTestequal;
  147. var
  148. i : Currency;
  149. j : Currency;
  150. result : boolean;
  151. begin
  152. result := true;
  153. Write('Currency = Currency test...');
  154. i := 1000.0;
  155. j := 1000.0;
  156. if not (trunc(i) = trunc(j)) then
  157. result := false;
  158. if not (trunc(i) = trunc(1000.0)) then
  159. result := false;
  160. if not result then
  161. Fail
  162. else
  163. WriteLn('Success.');
  164. end;
  165. procedure CurrencyTestnotequal;
  166. var
  167. i : Currency;
  168. j : Currency;
  169. result : boolean;
  170. begin
  171. result := true;
  172. Write('Currency <> Currency test...');
  173. i := 1000.0;
  174. j := 1000.0;
  175. if (trunc(i) <> trunc(j)) then
  176. result := false;
  177. if (trunc(i) <> trunc(1000.0)) then
  178. result := false;
  179. if not result then
  180. Fail
  181. else
  182. WriteLn('Success.');
  183. end;
  184. procedure CurrencyTestle;
  185. var
  186. i : Currency;
  187. j : Currency;
  188. result : boolean;
  189. begin
  190. result := true;
  191. Write('Currency <= Currency test...');
  192. i := 1000.0;
  193. j := 1000.0;
  194. if not (trunc(i) <= trunc(j)) then
  195. result := false;
  196. if not (trunc(i) <= trunc(1000.0)) then
  197. result := false;
  198. i := 10000.0;
  199. j := 999.0;
  200. if trunc(i) < trunc(j) then
  201. result := false;
  202. if trunc(i) < trunc(999.0) then
  203. result := false;
  204. if not result then
  205. Fail
  206. else
  207. WriteLn('Success.');
  208. end;
  209. procedure CurrencyTestge;
  210. var
  211. i : Currency;
  212. j : Currency;
  213. result : boolean;
  214. begin
  215. result := true;
  216. Write('Currency >= Currency test...');
  217. i := 1000.0;
  218. j := 1000.0;
  219. if not (trunc(i) >= trunc(j)) then
  220. result := false;
  221. if not (trunc(i) >= trunc(1000.0)) then
  222. result := false;
  223. i := 999.0;
  224. j := 1000.0;
  225. if trunc(i) > trunc(j) then
  226. result := false;
  227. if trunc(i) > trunc(999.0) then
  228. result := false;
  229. if not result then
  230. Fail
  231. else
  232. WriteLn('Success.');
  233. end;
  234. Begin
  235. CurrencyTestEqual;
  236. CurrencyTestNotEqual;
  237. CurrencyTestLE;
  238. CurrencyTestGE;
  239. CurrencyTestSub;
  240. CurrencyTestAdd;
  241. CurrencyTestDiv;
  242. CurrencyTestMul;
  243. { CurrencyTestComplex;}
  244. end.
  245. {
  246. $Log$
  247. Revision 1.1 2002-09-18 18:29:07 carl
  248. * currency cg tests (tested againt Delphi 3)
  249. }