[fpc-devel] Bug 29760 on FPC 3.0 Win64
LacaK
lacak at zoznam.sk
Fri Mar 11 11:50:05 CET 2016
>
>> > So wouldn't be better have less bigger test units for example
>> "tcurrency" which will do complex testing for for example all
>> math.operations with currency data type ?
>> > (as opposed to have lot of fragments in lot of anonymous files)
>> >
>>
>> Feel free to write such a test.
>>
> See attached file. Is this way or not (may be that somewhat must be
> IFDEFed for platforms where given data type does not exists?) ?
> (as I do not know compiler internals, I do not know which makes sense
> to test and which is redundant or irrelevant)
Updated file.
If you find it useful add it please to "tests/test" and/or replace
"tw28748.pp" (as it is subset of this)
Or give mee feedback what should be changed, added or so.
-Laco.
-------------- next part --------------
program tcurrency;
{ test basic mathematical operations (+,-,*,/) using currency data type }
var
c1, c2: Currency;
d: Double;
i: Integer;
i64: int64;
begin
writeln('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('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('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;
end.
More information about the fpc-devel
mailing list