numir.testing
Various testing
utility on the ndslice (e.g., approxEqual, assertShapeEqual)
-
Declaration
pure nothrow @nogc bool
approxEqual
(L, R, V)(Llhs
, Rrhs
, VmaxRelDiff
= 0.01, VmaxAbsDiff
= 1e-05) if (isSlice!L && isSlice!R);testing function for float-point slices
Examples
import mir.ndslice : sliced; static immutable eps = 1e-6; static immutable _a = [1.0, 0.0, 0.0, 1.0]; auto a = _a.sliced(2, 2); static immutable _b = [1.0, eps, -eps, 1.0]; auto b = _b.sliced(2, 2); assert(approxEqual(a, b, eps*2, eps*2)); assert(!approxEqual(a, b, eps/2, eps/2));
-
Declaration
pure nothrow @nogc void
assertShapeEqual
(L, R)(Llhs
, Rrhs
) if (isSlice!L && isSlice!R);testing function for shape equality
Examples
import mir.ndslice : iota; import core.exception; // test OK assertShapeEqual(iota(3, 4), iota(3, 4)); assertShapeEqual(iota(0), iota(0)); // test NG static assert(!__traits(compiles, assertShapeEqual(iota(3, 4), iota(3, 4, 5)))); try { assertShapeEqual(iota(3, 4), iota(3, 2)); assert(false); } catch (AssertError) { // OK! }