Skip to content

Commit 4c9375c

Browse files
committed
Added TestShuffle
1 parent 837f9cc commit 4c9375c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Test/ArrayListTestCase.pas

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ TTestCaseArrayList = class(TTestCase)
3535
procedure TestPack;
3636
procedure TestReverse;
3737
procedure TestSort;
38+
procedure TestShuffle;
3839
end;
3940

4041
implementation
@@ -353,6 +354,36 @@ procedure TTestCaseArrayList.TestSort;
353354
CheckEqualsList(L, ArrayList([1, 2, 3, 4, 5, 6, 7, 8, 9]));
354355
end;
355356

357+
procedure TTestCaseArrayList.TestShuffle;
358+
var
359+
Src, Dest: IList;
360+
Statistics: IList;
361+
M: IMap;
362+
I, J, N: Integer;
363+
begin
364+
Src := ArrayList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
365+
Statistics := TArrayList.Create(Src.Count);
366+
for I := 0 to Src.Count - 1 do
367+
Statistics[I] := HashMap([0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0]);
368+
for I := 0 to 99999 do begin
369+
Dest := TArrayList.Create(Src);
370+
Dest.Shuffle;
371+
for J := 0 to Statistics.Count - 1 do begin
372+
M := VarToMap(Statistics[J]);
373+
N := M.Get(Dest[J]);
374+
Inc(N);
375+
M.Put(Dest[J], Variant(N));
376+
end;
377+
end;
378+
for I := 0 to Statistics.Count - 1 do begin
379+
for J := 0 to Statistics[I].Count - 1 do begin
380+
N := Statistics[I].Values.Get(J);
381+
Check((9500 < N) and (N < 10500), Variant(N));
382+
end;
383+
end;
384+
385+
end;
386+
356387
initialization
357388
TestFramework.RegisterTest(TTestCaseArrayList.Suite);
358389

0 commit comments

Comments
 (0)