mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 15:10:46 +03:00
Fix unpredictableSeed so that rndstuff can be used in @safe code
Allows: 1) canFind's tests to be @safe 2) allows the remainder of find's tests to be @safe
This commit is contained in:
parent
3200b08644
commit
f70e1e41e4
2 changed files with 7 additions and 7 deletions
|
@ -5520,7 +5520,7 @@ if (Ranges.length > 1 && is(typeof(startsWith!pred(haystack, needles))))
|
||||||
assert(find("abc", "bc").length == 2);
|
assert(find("abc", "bc").length == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
import std.string : toUpper;
|
import std.string : toUpper;
|
||||||
|
|
||||||
|
@ -5549,7 +5549,7 @@ unittest
|
||||||
assert(find!(f)(s, "hello").length == 3);
|
assert(find!(f)(s, "hello").length == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
debug(std_algorithm) scope(success)
|
debug(std_algorithm) scope(success)
|
||||||
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
|
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
|
||||||
|
@ -12109,7 +12109,7 @@ template canFind(alias pred="a == b")
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
assert(canFind([0, 1, 2, 3], 2) == true);
|
assert(canFind([0, 1, 2, 3], 2) == true);
|
||||||
assert(canFind([0, 1, 2, 3], [1, 2], [2, 3]));
|
assert(canFind([0, 1, 2, 3], [1, 2], [2, 3]));
|
||||||
|
@ -12122,7 +12122,7 @@ unittest
|
||||||
assert(canFind([0, 1, 2, 3], [1, 3], [2, 4]) == 0);
|
assert(canFind([0, 1, 2, 3], [1, 3], [2, 4]) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
debug(std_algorithm) scope(success)
|
debug(std_algorithm) scope(success)
|
||||||
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
|
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
|
||||||
|
@ -12134,7 +12134,7 @@ unittest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
assert(equal!(canFind!"a < b")([[1, 2, 3], [7, 8, 9]], [2, 8]));
|
assert(equal!(canFind!"a < b")([[1, 2, 3], [7, 8, 9]], [2, 8]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1114,7 +1114,7 @@ auto n = rnd.front;
|
||||||
----
|
----
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@property uint unpredictableSeed()
|
@property uint unpredictableSeed() @trusted
|
||||||
{
|
{
|
||||||
static bool seeded;
|
static bool seeded;
|
||||||
static MinstdRand0 rand;
|
static MinstdRand0 rand;
|
||||||
|
@ -1128,7 +1128,7 @@ auto n = rnd.front;
|
||||||
return cast(uint) (TickDuration.currSystemTick.length ^ rand.front);
|
return cast(uint) (TickDuration.currSystemTick.length ^ rand.front);
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
// not much to test here
|
// not much to test here
|
||||||
auto a = unpredictableSeed;
|
auto a = unpredictableSeed;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue