tset1.pp 3.9 KB

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