testset.pp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. {
  2. $Id$
  3. Program to test set functions
  4. }
  5. { $define FPC_HAS_SET_INEQUALITIES
  6. <,> <= and >= are not implemented yet (PM) }
  7. program TestSet;
  8. Procedure InitMSTimer;
  9. begin
  10. end;
  11. {Get MS Timer}
  12. Function MSTimer:longint;
  13. begin
  14. MSTimer:=0;
  15. end;
  16. const
  17. Lval=2000;
  18. VAR Box1, Box2: ARRAY [0..255] OF BYTE;
  19. OneWOTwo, TwoWOOne,
  20. UnionSet, InterSet,
  21. Set1, Set2, Set3: SET OF BYTE;
  22. K, MaxNr, L,
  23. N, Low, Hi: INTEGER;
  24. Start: LONGINT;
  25. begin
  26. WriteLn ('Set operators functional and speed test');
  27. WriteLn;
  28. RandSeed := 17;
  29. for L := 0 TO 255 DO begin
  30. Box1 [L] := L;
  31. end;
  32. MaxNr := 255;
  33. for L := 0 TO 255 DO begin
  34. K := Random (MaxNr+1);
  35. Box2 [L] := Box1 [K];
  36. Box1 [K] := Box1 [MaxNr];
  37. Dec (MaxNr);
  38. end;
  39. Start :=MSTimer;
  40. Set1 := [];
  41. Set2 := [];
  42. for L := 0 TO 255 DO begin
  43. Set1 := Set1 + [Box2 [L]];
  44. if NOT (Box2 [L] IN Set1) then begin
  45. WriteLn ('error in AddElem or InSet functions');
  46. Halt;
  47. end;
  48. Set2 := Set2 + [Box2 [L]] + [];
  49. end;
  50. {$ifdef FPC_HAS_SET_INEQUALITIES }
  51. if (Set1 <> Set2) OR (NOT (Set1 <= Set2)) OR (NOT (Set1 >= Set2)) then begin
  52. {$else FPC_HAS_SET_INEQUALITIES }
  53. if (Set1 <> Set2) then begin
  54. {$endif FPC_HAS_SET_INEQUALITIES }
  55. WriteLn ('error in relational operators 1');
  56. Halt;
  57. end;
  58. for L := 0 TO 255 DO begin
  59. Set1 := Set1 - [Box2 [L]];
  60. if Box2 [L] IN Set1 then begin
  61. WriteLn ('error in set difference 1');
  62. Halt;
  63. end;
  64. end;
  65. if Set1 <> [] then begin
  66. WriteLn ('error in set difference 2');
  67. Halt;
  68. end;
  69. for L := 1 TO LVal DO begin
  70. REPEAT
  71. Low := Random (256);
  72. Hi := Random (256);
  73. UNTIL Low <= Hi;
  74. Set1 := [];
  75. Set1 := Set1 + [Low..Hi];
  76. for K := 0 TO 255 DO begin
  77. if (K IN Set1) AND ((K < Low) OR (K > Hi)) then begin
  78. WriteLn ('wrong set inclusion in add range');
  79. Halt;
  80. end;
  81. if (NOT (K IN Set1)) AND ((K >= Low) AND (K <= Hi)) then begin
  82. WriteLn ('wrong set exclusion in add range');
  83. Halt;
  84. end;
  85. end;
  86. end;
  87. for L := 1 TO LVal DO begin
  88. Set1 := [];
  89. Set2 := [];
  90. for K := 1 TO 10 DO begin
  91. Low := Random (256);
  92. Hi := Random (256);
  93. Set2:= Set1 + [Low..Hi];
  94. {$ifdef FPC_HAS_SET_INEQUALITIES }
  95. if (Set1 >= Set2) AND (Set1 <> Set2) then begin
  96. {$else FPC_HAS_SET_INEQUALITIES }
  97. if (Set1 <> Set2) then begin
  98. {$endif FPC_HAS_SET_INEQUALITIES }
  99. WriteLn ('error in relational operators 2');
  100. Halt;
  101. end;
  102. {$ifdef FPC_HAS_SET_INEQUALITIES }
  103. if NOT (Set1 <= Set2) then begin
  104. WriteLn ('error in relational operators 3');
  105. Halt;
  106. end;
  107. {$endif FPC_HAS_SET_INEQUALITIES }
  108. Set1 := Set2;
  109. end;
  110. end;
  111. for L := 1 TO LVal DO begin
  112. Set1 := [];
  113. for K := 1 TO 10 DO begin
  114. Low := Random (256);
  115. Hi := Random (256);
  116. Set1:= Set1 + [Low..Hi];
  117. end;
  118. Set2 := [];
  119. for K := 1 TO 10 DO begin
  120. Low := Random (256);
  121. Hi := Random (256);
  122. Set2:= Set2 + [Low..Hi];
  123. end;
  124. OneWOTwo := Set1 - Set2;
  125. TwoWOOne := Set2 - Set1;
  126. InterSet := Set1 * Set2;
  127. UnionSet := Set1 + Set2;
  128. if InterSet <> (Set2 * Set1) then begin
  129. WriteLn ('error in set difference');
  130. Halt;
  131. end;
  132. if (InterSet + OneWOTwo) <> Set1 then begin
  133. WriteLn ('error in set difference or intersection');
  134. Halt;
  135. end;
  136. if (InterSet + TwoWOOne) <> Set2 then begin
  137. WriteLn ('error in set difference or intersection');
  138. Halt;
  139. end;
  140. if (OneWOTwo + TwoWOOne + InterSet) <> UnionSet then begin
  141. WriteLn ('error in set union, intersection or difference');
  142. Halt;
  143. end;
  144. end;
  145. Start:=MSTimer-Start;
  146. WriteLn('Set test completes in ',Start,' ms');
  147. end.