numir.testing

Various testing utility on the ndslice (e.g., approxEqual, assertShapeEqual)

  • Declaration

    pure nothrow @nogc bool approxEqual(L, R, V)(L lhs, R rhs, V maxRelDiff = 0.01, V maxAbsDiff = 1e-05) if (isSlice!L && isSlice!R);

    testing function for float-point slices

    Examples

    1. 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)(L lhs, R rhs) if (isSlice!L && isSlice!R);

    testing function for shape equality

    Examples

    1. 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! }