mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 07:00:37 +03:00
Turn min() unittest into ddoc'd example.
This commit is contained in:
parent
f827ffaa24
commit
6452bf89e6
1 changed files with 5 additions and 4 deletions
|
@ -1357,10 +1357,9 @@ MinType!T min(T...)(T args)
|
||||||
return cast(typeof(return)) (chooseA ? a : b);
|
return cast(typeof(return)) (chooseA ? a : b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
@safe unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
debug(std_algorithm) scope(success)
|
|
||||||
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
|
|
||||||
int a = 5;
|
int a = 5;
|
||||||
short b = 6;
|
short b = 6;
|
||||||
double c = 2;
|
double c = 2;
|
||||||
|
@ -1370,13 +1369,15 @@ MinType!T min(T...)(T args)
|
||||||
auto e = min(a, b, c);
|
auto e = min(a, b, c);
|
||||||
static assert(is(typeof(e) == double));
|
static assert(is(typeof(e) == double));
|
||||||
assert(e == 2);
|
assert(e == 2);
|
||||||
// mixed signedness test
|
|
||||||
|
// With arguments of mixed signedness, the return type is the one that can
|
||||||
|
// store the lowest values.
|
||||||
a = -10;
|
a = -10;
|
||||||
uint f = 10;
|
uint f = 10;
|
||||||
static assert(is(typeof(min(a, f)) == int));
|
static assert(is(typeof(min(a, f)) == int));
|
||||||
assert(min(a, f) == -10);
|
assert(min(a, f) == -10);
|
||||||
|
|
||||||
//Test user-defined types
|
// User-defined types that support comparison with < are supported.
|
||||||
import std.datetime;
|
import std.datetime;
|
||||||
assert(min(Date(2012, 12, 21), Date(1982, 1, 4)) == Date(1982, 1, 4));
|
assert(min(Date(2012, 12, 21), Date(1982, 1, 4)) == Date(1982, 1, 4));
|
||||||
assert(min(Date(1982, 1, 4), Date(2012, 12, 21)) == Date(1982, 1, 4));
|
assert(min(Date(1982, 1, 4), Date(2012, 12, 21)) == Date(1982, 1, 4));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue