Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

mir.test

Testing utilities
Authors:
Ilya Yaroshenko
struct ShouldApprox(T, F = T) if ((__traits(isFloating, T) || __traits(hasMember, T, "approxEqual")) && __traits(isFloating, F));

ShouldApprox!T shouldApprox(T)(const T value, const T maxRelDiff = T(9.53674e-07F), const T maxAbsDiff = T(9.53674e-07F))
if (__traits(isFloating, T));

ShouldApprox!(T, F) shouldApprox(T, F)(const T value, const F maxRelDiff = double(9.53674e-07F), const F maxAbsDiff = double(9.53674e-07F))
if (__traits(hasMember, T, "approxEqual") && __traits(isFloating, F));
Examples:
1.0.shouldApprox == 1 + 9e-7;
shouldApprox(1 + 9e-7, 1e-6, 1e-6) == 1;
Examples:
static struct C {
    double re, im;
    auto approxEqual(C rhs, double maxRelDiff, double maxAbsDiff)
    {
        import mir.math.common: approxEqual;
        return approxEqual(re, rhs.re, maxRelDiff, maxAbsDiff) && approxEqual(im, rhs.im, maxRelDiff, maxAbsDiff);
    }
}
C(1.0, 1.0).shouldApprox == C(1 + 9e-7, 1 - 9e-7);
T value;
F maxRelDiff;
F maxAbsDiff;
pure nothrow @nogc @safe void opEquals(T expected, string file = __FILE__, int line = __LINE__);
struct Should(T);

Should!T should(T)(T value);
Examples:
1.0.should == 1;
should(1) == 1;

ubyte[] val = [0, 2, 3];
val.should == [0, 2, 3];
T value;
@trusted void opEquals(R)(const R expected, string file = __FILE__, int line = __LINE__);
void should(alias fun = "a == b", T, R)(const T value, const R expected, string file = __FILE__, int line = __LINE__);
Examples:
1.0.should!"a < b"(1.3);