123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- program tcurrency;
- { test basic mathematical operations (+,-,*,/) using currency data type }
- var
- c1, c2: Currency;
- d: Double;
- i: Integer;
- i64: int64;
- begin
- write('Currency and Double ...');
- // addition double
- d := 1;
- c1 := 2;
- c2 := 3;
- if c1+d <> c2 then begin
- writeln('Invalid currency+double=', c1+d, ', but expected ', c2);
- halt(1);
- end;
- // subtraction double
- d := 3;
- c1 := 2;
- c2 := -1;
- if c1-d <> c2 then begin
- writeln('Invalid currency-double=', c1-d, ', but expected ', c2);
- halt(1);
- end;
- // multiplication double
- d := -100;
- c1 := 12.34;
- c2 := -1234;
- if d*c1 <> c2 then begin
- writeln('Invalid currency*double=', d*c1, ', but expected ', c2);
- halt(1);
- end;
- // division double
- d := 100;
- c1 := 12.34;
- c2 := 0.1234;
- if c1/d <> c2 then begin
- writeln('Invalid currency/double=', c1/d, ', but expected ', c2);
- halt(1);
- end;
- writeln(' Passed');
- write('Currency and Integer ...');
- // addition integer
- i := 1;
- c1 := 2;
- c2 := 3;
- if c1+i <> c2 then begin
- writeln('Invalid currency+integer=', c1+i, ', but expected ', c2);
- halt(2);
- end;
- // subtraction integer
- i := 10;
- c1 := -2;
- c2 := -12;
- if c1-i <> c2 then begin
- writeln('Invalid currency-integer=', c1-i, ', but expected ', c2);
- halt(2);
- end;
- // multiplication integer
- i := 100;
- c1 := 12.34;
- c2 := 1234;
- if i*c1 <> c2 then begin
- writeln('Invalid currency*integer=', i*c1, ', but expected ', c2);
- halt(2);
- end;
- // division integer
- i := 1000;
- c1 := 123.4;
- c2 := 0.1234;
- if c1/i <> c2 then begin
- writeln('Invalid currency/integer=', c1/i, ', but expected ', c2);
- halt(2);
- end;
- writeln(' Passed');
- write('Currency and Int64 ...');
- // addition int64
- i64 := 1;
- c1 := 12.3456;
- c2 := 13.3456;
- if c1+i64 <> c2 then begin
- writeln('Invalid currency+int64=', c1+i64, ', but expected ', c2);
- halt(3);
- end;
- // subtraction int64
- i64 := 100;
- c1 := 12.3456;
- c2 := -87.6544;
- if c1-i64 <> c2 then begin
- writeln('Invalid currency-int64=', c1-i64, ', but expected ', c2);
- halt(3);
- end;
- // multiplication int64
- i64 := -10000;
- c1 := 12.3456;
- c2 := -123456;
- if i64*c1 <> c2 then begin
- writeln('Invalid currency*int64=', i64*c1, ', but expected ', c2);
- halt(3);
- end;
- // division int64
- i64 := -10000;
- c1 := 123456;
- c2 := -12.3456;
- if c1/i64 <> c2 then begin
- writeln('Invalid currency/int64=', c1/i64, ', but expected ', c2);
- halt(3);
- end;
- writeln(' Passed');
- end.
|