mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 06:30:28 +03:00
Derandomize std.algorithm.sorting
This commit is contained in:
parent
0fef09a311
commit
b46bd2951f
1 changed files with 43 additions and 31 deletions
|
@ -883,9 +883,13 @@ if (ss == SwapStrategy.unstable && isRandomAccessRange!Range
|
|||
|
||||
@safe unittest
|
||||
{
|
||||
import std.random : uniform;
|
||||
import std.random : Random, uniform, unpredictableSeed;
|
||||
|
||||
auto a = new int[](uniform(0, 100));
|
||||
immutable uint[] seeds = [3923355730, 1927035882, unpredictableSeed];
|
||||
foreach (s; seeds)
|
||||
{
|
||||
auto r = Random(s);
|
||||
auto a = new int[](uniform(0, 100, r));
|
||||
foreach (ref e; a)
|
||||
{
|
||||
e = uniform(0, 50);
|
||||
|
@ -904,6 +908,7 @@ if (ss == SwapStrategy.unstable && isRandomAccessRange!Range
|
|||
{
|
||||
assert(e > 25);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// makeIndex
|
||||
|
@ -3500,14 +3505,20 @@ private T[] randomArray(Flag!"exactSize" flag = No.exactSize, T = int)(
|
|||
{
|
||||
import std.algorithm.comparison : max, min;
|
||||
import std.algorithm.iteration : reduce;
|
||||
import std.random : uniform;
|
||||
import std.random : Random, uniform, unpredictableSeed;
|
||||
|
||||
debug(std_algorithm) scope(success)
|
||||
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
|
||||
|
||||
int[] a = new int[uniform(1, 10000)];
|
||||
foreach (ref e; a) e = uniform(-1000, 1000);
|
||||
auto k = uniform(0, a.length);
|
||||
immutable uint[] seeds = [90027751, 2709791795, 1374631933, 995751648, 3541495258, 984840953, unpredictableSeed];
|
||||
foreach (s; seeds)
|
||||
{
|
||||
auto r = Random(s);
|
||||
|
||||
int[] a = new int[uniform(1, 10000, r)];
|
||||
foreach (ref e; a) e = uniform(-1000, 1000, r);
|
||||
|
||||
auto k = uniform(0, a.length, r);
|
||||
topN(a, k);
|
||||
if (k > 0)
|
||||
{
|
||||
|
@ -3519,6 +3530,7 @@ private T[] randomArray(Flag!"exactSize" flag = No.exactSize, T = int)(
|
|||
auto right = reduce!min(a[k + 1 .. $]);
|
||||
assert(right >= a[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// bug 12987
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue