mirror of
https://github.com/dlang/phobos.git
synced 2025-05-04 00:54:05 +03:00
Use assertThrown
in reduce unittest
This commit is contained in:
parent
2572cef9d4
commit
096ae6ab87
1 changed files with 14 additions and 21 deletions
|
@ -949,8 +949,8 @@ unittest
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
debug(std_algorithm) scope(success)
|
import std.exception : assertThrown;
|
||||||
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
|
|
||||||
double[] a = [ 3, 4 ];
|
double[] a = [ 3, 4 ];
|
||||||
auto r = reduce!("a + b")(0.0, a);
|
auto r = reduce!("a + b")(0.0, a);
|
||||||
assert(r == 7);
|
assert(r == 7);
|
||||||
|
@ -1000,16 +1000,10 @@ unittest
|
||||||
assert(reduce!("a + b", max)(tuple(5, 0), oa) == tuple(hundredSum + 5, 99));
|
assert(reduce!("a + b", max)(tuple(5, 0), oa) == tuple(hundredSum + 5, 99));
|
||||||
|
|
||||||
// Test for throwing on empty range plus no seed.
|
// Test for throwing on empty range plus no seed.
|
||||||
try {
|
assertThrown(reduce!"a + b"([1, 2][0..0]));
|
||||||
reduce!"a + b"([1, 2][0..0]);
|
|
||||||
assert(0);
|
|
||||||
} catch(Exception) {}
|
|
||||||
|
|
||||||
oa.actEmpty = true;
|
oa.actEmpty = true;
|
||||||
try {
|
assertThrown(reduce!"a + b"(oa));
|
||||||
reduce!"a + b"(oa);
|
|
||||||
assert(0);
|
|
||||||
} catch(Exception) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
|
@ -1039,7 +1033,7 @@ unittest
|
||||||
enum foo = "a + 0.5 * b";
|
enum foo = "a + 0.5 * b";
|
||||||
auto r = [0, 1, 2, 3];
|
auto r = [0, 1, 2, 3];
|
||||||
auto r1 = reduce!foo(r);
|
auto r1 = reduce!foo(r);
|
||||||
auto r2 = reduce!(foo, foo,)(r);
|
auto r2 = reduce!(foo, foo)(r);
|
||||||
assert(r1 == 3);
|
assert(r1 == 3);
|
||||||
assert(r2 == tuple(3, 3));
|
assert(r2 == tuple(3, 3));
|
||||||
}
|
}
|
||||||
|
@ -1100,17 +1094,16 @@ unittest //12569
|
||||||
static assert(!is(typeof(reduce!(min, max)(tuple(c), "hello"))));
|
static assert(!is(typeof(reduce!(min, max)(tuple(c), "hello"))));
|
||||||
static assert(!is(typeof(reduce!(min, max)(tuple(c, c, c), "hello"))));
|
static assert(!is(typeof(reduce!(min, max)(tuple(c, c, c), "hello"))));
|
||||||
|
|
||||||
//Uncomment these to make sure a correct error message is generated
|
|
||||||
|
|
||||||
//Error: static assert "Seed dchar should be a Tuple"
|
//"Seed dchar should be a Tuple"
|
||||||
version(none) reduce!(min, max)(c, "hello"); // error
|
static assert(!is(typeof(reduce!(min, max)(c, "hello"))));
|
||||||
//Error: static assert "Seed (dchar) does not have the correct amount of fields (should be 2)"
|
//"Seed (dchar) does not have the correct amount of fields (should be 2)"
|
||||||
version(none) reduce!(min, max)(tuple(c), "hello"); // error
|
static assert(!is(typeof(reduce!(min, max)(tuple(c), "hello"))));
|
||||||
//Error: static assert "Seed (dchar, dchar, dchar) does not have the correct amount of fields (should be 2)"
|
//"Seed (dchar, dchar, dchar) does not have the correct amount of fields (should be 2)"
|
||||||
version(none) reduce!(min, max)(tuple(c, c, c), "hello"); // error
|
static assert(!is(typeof(reduce!(min, max)(tuple(c, c, c), "hello"))));
|
||||||
//Error: static assert "Incompatable function/seed/element: all(alias pred = "a")/int/dchar"
|
//"Incompatable function/seed/element: all(alias pred = "a")/int/dchar"
|
||||||
version(none) reduce!all(1, "hello"); // error
|
static assert(!is(typeof(reduce!all(1, "hello"))));
|
||||||
version(none) reduce!(all, all)(tuple(1, 1), "hello"); // error
|
static assert(!is(typeof(reduce!(all, all)(tuple(1, 1), "hello"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
// sum
|
// sum
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue