tcurrency1.pp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. program tcurrency;
  2. { test basic mathematical operations (+,-,*,/) using currency data type }
  3. var
  4. c1, c2: Currency;
  5. d: Double;
  6. i: Integer;
  7. i64: int64;
  8. begin
  9. write('Currency and Double ...');
  10. // addition double
  11. d := 1;
  12. c1 := 2;
  13. c2 := 3;
  14. if c1+d <> c2 then begin
  15. writeln('Invalid currency+double=', c1+d, ', but expected ', c2);
  16. halt(1);
  17. end;
  18. // subtraction double
  19. d := 3;
  20. c1 := 2;
  21. c2 := -1;
  22. if c1-d <> c2 then begin
  23. writeln('Invalid currency-double=', c1-d, ', but expected ', c2);
  24. halt(1);
  25. end;
  26. // multiplication double
  27. d := -100;
  28. c1 := 12.34;
  29. c2 := -1234;
  30. if d*c1 <> c2 then begin
  31. writeln('Invalid currency*double=', d*c1, ', but expected ', c2);
  32. halt(1);
  33. end;
  34. // division double
  35. d := 100;
  36. c1 := 12.34;
  37. c2 := 0.1234;
  38. if c1/d <> c2 then begin
  39. writeln('Invalid currency/double=', c1/d, ', but expected ', c2);
  40. halt(1);
  41. end;
  42. writeln(' Passed');
  43. write('Currency and Integer ...');
  44. // addition integer
  45. i := 1;
  46. c1 := 2;
  47. c2 := 3;
  48. if c1+i <> c2 then begin
  49. writeln('Invalid currency+integer=', c1+i, ', but expected ', c2);
  50. halt(2);
  51. end;
  52. // subtraction integer
  53. i := 10;
  54. c1 := -2;
  55. c2 := -12;
  56. if c1-i <> c2 then begin
  57. writeln('Invalid currency-integer=', c1-i, ', but expected ', c2);
  58. halt(2);
  59. end;
  60. // multiplication integer
  61. i := 100;
  62. c1 := 12.34;
  63. c2 := 1234;
  64. if i*c1 <> c2 then begin
  65. writeln('Invalid currency*integer=', i*c1, ', but expected ', c2);
  66. halt(2);
  67. end;
  68. // division integer
  69. i := 1000;
  70. c1 := 123.4;
  71. c2 := 0.1234;
  72. if c1/i <> c2 then begin
  73. writeln('Invalid currency/integer=', c1/i, ', but expected ', c2);
  74. halt(2);
  75. end;
  76. writeln(' Passed');
  77. write('Currency and Int64 ...');
  78. // addition int64
  79. i64 := 1;
  80. c1 := 12.3456;
  81. c2 := 13.3456;
  82. if c1+i64 <> c2 then begin
  83. writeln('Invalid currency+int64=', c1+i64, ', but expected ', c2);
  84. halt(3);
  85. end;
  86. // subtraction int64
  87. i64 := 100;
  88. c1 := 12.3456;
  89. c2 := -87.6544;
  90. if c1-i64 <> c2 then begin
  91. writeln('Invalid currency-int64=', c1-i64, ', but expected ', c2);
  92. halt(3);
  93. end;
  94. // multiplication int64
  95. i64 := -10000;
  96. c1 := 12.3456;
  97. c2 := -123456;
  98. if i64*c1 <> c2 then begin
  99. writeln('Invalid currency*int64=', i64*c1, ', but expected ', c2);
  100. halt(3);
  101. end;
  102. // division int64
  103. i64 := -10000;
  104. c1 := 123456;
  105. c2 := -12.3456;
  106. if c1/i64 <> c2 then begin
  107. writeln('Invalid currency/int64=', c1/i64, ', but expected ', c2);
  108. halt(3);
  109. end;
  110. writeln(' Passed');
  111. end.