Turn min() unittest into ddoc'd example.

This commit is contained in:
H. S. Teoh 2015-09-08 22:00:25 -07:00
parent f827ffaa24
commit 6452bf89e6

View file

@ -1357,10 +1357,9 @@ MinType!T min(T...)(T args)
return cast(typeof(return)) (chooseA ? a : b);
}
///
@safe unittest
{
debug(std_algorithm) scope(success)
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
int a = 5;
short b = 6;
double c = 2;
@ -1370,13 +1369,15 @@ MinType!T min(T...)(T args)
auto e = min(a, b, c);
static assert(is(typeof(e) == double));
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;
uint f = 10;
static assert(is(typeof(min(a, f)) == int));
assert(min(a, f) == -10);
//Test user-defined types
// User-defined types that support comparison with < are supported.
import std.datetime;
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));