mirror of
https://github.com/dlang/phobos.git
synced 2025-05-03 00:20:26 +03:00
Minor tweaks
This commit is contained in:
parent
6c7d0e2ef1
commit
762b0b4881
1 changed files with 10 additions and 3 deletions
|
@ -4037,7 +4037,9 @@ if (isInputRange!Range && !isInfinite!Range &&
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns an array of the minimum and maximum element in `r`.
|
/** Returns an array of the minimum and maximum element in `r`.
|
||||||
* Makes `< 3n/2` comparisons.
|
* Performs `< 3n/2` comparisons, unlike the naive `< 2n`.
|
||||||
|
* Params:
|
||||||
|
* r = The range to traverse.
|
||||||
*/
|
*/
|
||||||
// TODO alias map = a => a
|
// TODO alias map = a => a
|
||||||
ElementType!Range[2] extrema(Range)(Range r)
|
ElementType!Range[2] extrema(Range)(Range r)
|
||||||
|
@ -4082,15 +4084,20 @@ in (!r.empty)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
///
|
||||||
|
@safe unittest
|
||||||
{
|
{
|
||||||
assert(extrema([5,2,9,4,1]) == [1, 9]);
|
assert(extrema([5,2,9,4,1]) == [1, 9]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@safe unittest
|
||||||
|
{
|
||||||
assert(extrema([8,3,7,4,9]) == [3, 9]);
|
assert(extrema([8,3,7,4,9]) == [3, 9]);
|
||||||
assert(extrema([1,5,3,2]) == [1, 5]);
|
assert(extrema([1,5,3,2]) == [1, 5]);
|
||||||
assert(extrema([2,3,3,2]) == [2, 3]);
|
assert(extrema([2,3,3,2]) == [2, 3]);
|
||||||
|
|
||||||
version (StdRandomTests)
|
version (StdRandomTests)
|
||||||
foreach (i; 0..1000)
|
foreach (i; 0 .. 1000)
|
||||||
{
|
{
|
||||||
import std.random, std.range;
|
import std.random, std.range;
|
||||||
auto arr = generate!(() => uniform(0, 100)).takeExactly(uniform(1, 10)).array;
|
auto arr = generate!(() => uniform(0, 100)).takeExactly(uniform(1, 10)).array;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue