tw18704.pp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. {$APPTYPE CONSOLE}
  2. program CurrencyFormatTest;
  3. (*
  4. Test subject: .\rtl\inc\sstrings.inc::fpc_shortstr_currency
  5. Test FPC having problems: r21245, win32-i386
  6. *)
  7. type
  8. TTestCase = record
  9. value : currency;
  10. expect : array [0..5] of string;
  11. end;
  12. const
  13. test_cases : array [0..19] of TTestCase = (
  14. ( value : 0.9500; expect : ('0.95000','0.9500','0.950','0.95','1.0','1')),
  15. ( value :-0.9500; expect : ('-0.95000','-0.9500','-0.950','-0.95','-1.0','-1')),
  16. ( value : 1.4445; expect : ('1.44450','1.4445','1.445','1.44','1.4','1')),
  17. ( value :-1.4445; expect : ('-1.44450','-1.4445','-1.445','-1.44','-1.4','-1')),
  18. ( value : 199.4445; expect : ('199.44450','199.4445','199.445','199.44','199.4','199')),
  19. ( value :-199.4445; expect : ('-199.44450','-199.4445','-199.445','-199.44','-199.4','-199')),
  20. ( value : 1.9995; expect : ('1.99950','1.9995','2.000','2.00','2.0','2')),
  21. ( value :-1.9995; expect : ('-1.99950','-1.9995','-2.000','-2.00','-2.0','-2')),
  22. ( value : 99.9996; expect : ('99.99960','99.9996','100.000','100.00','100.0','100')),
  23. ( value :-99.9996; expect : ('-99.99960','-99.9996','-100.000','-100.00','-100.0','-100')),
  24. ( value : 0.9005; expect : ('0.90050','0.9005','0.901','0.90','0.9','1')),
  25. ( value :-0.9005; expect : ('-0.90050','-0.9005','-0.901','-0.90','-0.9','-1')),
  26. ( value : 0.0005; expect : ('0.00050','0.0005','0.001','0.00','0.0','0')),
  27. ( value :-0.0005; expect : ('-0.00050','-0.0005','-0.001','-0.00','-0.0','-0')), // NOTE!: at least Delphi 5/7 leaves '-' sign for zero!
  28. ( value : 0.0145; expect : ('0.01450','0.0145','0.015','0.01','0.0','0')),
  29. ( value :-0.0145; expect : ('-0.01450','-0.0145','-0.015','-0.01','-0.0','-0')), // NOTE!: at least Delphi 5/7 leaves '-' sign for zero!
  30. ( value : 99.9997; expect : ('99.99970','99.9997','100.000','100.00','100.0','100')),
  31. ( value :-99.9997; expect : ('-99.99970','-99.9997','-100.000','-100.00','-100.0','-100')),
  32. ( value : 999.9996; expect : ('999.99960','999.9996','1000.000','1000.00','1000.0','1000')),
  33. ( value :-999.9996; expect : ('-999.99960','-999.9996','-1000.000','-1000.00','-1000.0','-1000'))
  34. );
  35. function test_it(const test_case:TTestCase) : boolean;
  36. var
  37. expect,
  38. s : string;
  39. i : integer;
  40. c : char;
  41. ok : boolean;
  42. begin
  43. ok := true;
  44. writeln('Using Str for ',test_case.value);
  45. for i := high(test_case.expect) downto low(test_case.expect) do
  46. begin
  47. expect:=test_case.expect[high(test_case.expect)-i];
  48. str(test_case.value:0:i,s);
  49. if s=expect then
  50. c := ' '
  51. else
  52. begin
  53. c := '?';
  54. ok := false;
  55. end;
  56. writeln(c,' frac=',i,', expected=',expect,', got=',s);
  57. end;
  58. writeln;
  59. test_it := ok;
  60. end;
  61. var
  62. i : integer;
  63. ok : boolean;
  64. begin
  65. writeln;
  66. ok := true;
  67. for i := low(test_cases) to high(test_cases) do
  68. if not test_it(test_cases[i]) then
  69. ok := false;
  70. if not ok then
  71. begin
  72. writeln('Verdict: failed!');
  73. halt(1);
  74. end;
  75. end.