123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- { this tests the int routine }
- { Contrary to TP, int can be used in the constant section,
- just like in Delphi }
- program tint;
- {$ifdef VER1_0}
- {$define SKIP_CURRENCY_TEST}
- {$endif }
- const
- INT_RESULT_ONE = 1234;
- INT_VALUE_ONE = 1234.5678;
- INT_RESULT_CONST_ONE = Int(INT_VALUE_ONE);
- INT_RESULT_TWO = -1234;
- INT_VALUE_TWO = -1234.5678;
- INT_RESULT_CONST_TWO = Int(INT_VALUE_TWO);
- procedure fail;
- begin
- WriteLn('Failed!');
- halt(1);
- end;
- procedure test_int_real;
- var
- r: real;
- _success : boolean;
- Begin
- Write('Int() real testing...');
- _success := true;
- r:=INT_VALUE_ONE;
- if Int(r)<>INT_RESULT_ONE then
- _success:=false;
- if Int(INT_VALUE_ONE)<>INT_RESULT_ONE then
- _success:=false;
- r:=INT_VALUE_ONE;
- if Int(r)<>INT_RESULT_CONST_ONE then
- _success := false;
- r:=INT_VALUE_ONE;
- r:=Int(r);
- if r<>INT_RESULT_ONE then
- _success:=false;
- r:=Int(INT_VALUE_ONE);
- if r<>INT_RESULT_ONE then
- _success:=false;
- r:=INT_VALUE_TWO;
- if Int(r)<>INT_RESULT_TWO then
- _success:=false;
- if Int(INT_VALUE_TWO)<>INT_RESULT_TWO then
- _success:=false;
- r:=INT_VALUE_TWO;
- if Int(r)<>INT_RESULT_CONST_TWO then
- _success := false;
- r:=INT_VALUE_TWO;
- r:=Int(r);
- if r<>INT_RESULT_TWO then
- _success:=false;
- r:=Int(INT_VALUE_TWO);
- if r<>INT_RESULT_TWO then
- _success:=false;
- if not _success then
- fail;
- WriteLn('Success!');
- end;
- procedure test_int_single;
- var
- r: single;
- _success : boolean;
- Begin
- Write('Int() single testing...');
- _success := true;
- r:=INT_VALUE_ONE;
- if Int(r)<>INT_RESULT_ONE then
- _success:=false;
- if Int(INT_VALUE_ONE)<>INT_RESULT_ONE then
- _success:=false;
- r:=INT_VALUE_ONE;
- if Int(r)<>INT_RESULT_CONST_ONE then
- _success := false;
- r:=INT_VALUE_ONE;
- r:=Int(r);
- if r<>INT_RESULT_ONE then
- _success:=false;
- r:=Int(INT_VALUE_ONE);
- if r<>INT_RESULT_ONE then
- _success:=false;
- r:=INT_VALUE_TWO;
- if Int(r)<>INT_RESULT_TWO then
- _success:=false;
- if Int(INT_VALUE_TWO)<>INT_RESULT_TWO then
- _success:=false;
- r:=INT_VALUE_TWO;
- if Int(r)<>INT_RESULT_CONST_TWO then
- _success := false;
- r:=INT_VALUE_TWO;
- r:=Int(r);
- if r<>INT_RESULT_TWO then
- _success:=false;
- r:=Int(INT_VALUE_TWO);
- if r<>INT_RESULT_TWO then
- _success:=false;
- if not _success then
- fail;
- WriteLn('Success!');
- end;
- procedure test_int_double;
- var
- r: double;
- _success : boolean;
- Begin
- Write('Int() double testing...');
- _success := true;
- r:=INT_VALUE_ONE;
- if Int(r)<>INT_RESULT_ONE then
- _success:=false;
- if Int(INT_VALUE_ONE)<>INT_RESULT_ONE then
- _success:=false;
- r:=INT_VALUE_ONE;
- if Int(r)<>INT_RESULT_CONST_ONE then
- _success := false;
- r:=INT_VALUE_ONE;
- r:=Int(r);
- if r<>INT_RESULT_ONE then
- _success:=false;
- r:=Int(INT_VALUE_ONE);
- if r<>INT_RESULT_ONE then
- _success:=false;
- r:=INT_VALUE_TWO;
- if Int(r)<>INT_RESULT_TWO then
- _success:=false;
- if Int(INT_VALUE_TWO)<>INT_RESULT_TWO then
- _success:=false;
- r:=INT_VALUE_TWO;
- if Int(r)<>INT_RESULT_CONST_TWO then
- _success := false;
- r:=INT_VALUE_TWO;
- r:=Int(r);
- if r<>INT_RESULT_TWO then
- _success:=false;
- r:=Int(INT_VALUE_TWO);
- if r<>INT_RESULT_TWO then
- _success:=false;
- if not _success then
- fail;
- WriteLn('Success!');
- end;
- {$ifndef SKIP_CURRENCY_TEST}
- procedure test_int_currency;
- var
- r: currency;
- _success : boolean;
- Begin
- Write('Int() currency testing...');
- _success := true;
- r:=INT_VALUE_ONE;
- if Int(r)<>INT_RESULT_ONE then
- _success:=false;
- if not _success then
- fail;
- if Int(INT_VALUE_ONE)<>INT_RESULT_ONE then
- _success:=false;
- r:=INT_VALUE_ONE;
- if Int(r)<>INT_RESULT_CONST_ONE then
- _success := false;
- r:=INT_VALUE_ONE;
- r:=Int(r);
- if r<>INT_RESULT_ONE then
- _success:=false;
- r:=Int(INT_VALUE_ONE);
- if r<>INT_RESULT_ONE then
- _success:=false;
- if not _success then
- fail;
- r:=INT_VALUE_TWO;
- if Int(r)<>INT_RESULT_TWO then
- _success:=false;
- if Int(INT_VALUE_TWO)<>INT_RESULT_TWO then
- _success:=false;
- r:=INT_VALUE_TWO;
- if Int(r)<>INT_RESULT_CONST_TWO then
- _success := false;
- r:=INT_VALUE_TWO;
- r:=Int(r);
- if r<>INT_RESULT_TWO then
- _success:=false;
- r:=Int(INT_VALUE_TWO);
- if r<>INT_RESULT_TWO then
- _success:=false;
- if not _success then
- fail;
- WriteLn('Success!');
- end;
- {$endif SKIP_CURRENCY_TEST}
- Begin
- test_int_real;
- test_int_double;
- test_int_single;
- {$ifdef SKIP_CURRENCY_TEST}
- Writeln('Skipping currency test because its not supported by theis compiler');
- {$else SKIP_CURRENCY_TEST}
- test_int_currency;
- {$endif SKIP_CURRENCY_TEST}
- end.
|