tset1.pp 3.9 KB

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