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!TshouldApprox(T)(const Tvalue, const TmaxRelDiff= T(9.53674e-07F), const TmaxAbsDiff= T(9.53674e-07F))
if (__traits(isFloating, T));
ShouldApprox!(T, F)shouldApprox(T, F)(const Tvalue, const FmaxRelDiff= double(9.53674e-07F), const FmaxAbsDiff= 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(Texpected, stringfile= __FILE__, intline= __LINE__);
- struct
Should(T);
Should!Tshould(T)(Tvalue); - 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 Rexpected, stringfile= __FILE__, intline= __LINE__);
- void
should(alias fun = "a == b", T, R)(const Tvalue, const Rexpected, stringfile= __FILE__, intline= __LINE__); - Examples:
1.0.should!"a < b"(1.3);
Copyright © 2016-2026 by Ilya Yaroshenko | Page generated by
Ddoc on Wed Apr 8 13:47:04 2026