diff --git a/CHANGELOG.md b/CHANGELOG.md index 8485130..f796be7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.3.4 + +* Update to DLang frontend 2.91 +* Using std.math.isClose instead of .approxEquals +* Added .close as alias of .approxEquals + # v0.3.3 * .throw must be @trusted, to allow to catch Errors diff --git a/README.md b/README.md index ef0debe..dee1d57 100644 --- a/README.md +++ b/README.md @@ -58,14 +58,17 @@ assertion. 255.should.equal(10); // Throws an Exception "expected 255 to equal 10" ``` -#### `T approxEqual(U)(U other, U maxRelDiff = 1e-2, U maxAbsDiff = 1e-05, string file = __FILE__, size_t line = __LINE__);` +#### `T approxEqual(U)(U other, U maxRelDiff = CommonDefaultFor!(T,U), U maxAbsDiff = 0.0, string file = __FILE__, size_t line = __LINE__);` -Asserts for aproximated equality of float types. Returns the value wrapped around the -assertion. +Asserts for approximated equality of float types. Returns the value wrapped around the +assertion. See Phobos std.math.isClose(). ```d (1.0f).should.be.approxEqual(1.00000001); -(1.0f).should.not.be.approxEqual(1.001); +(1.0f).should.not.be.approxEqual(1.01); ``` +#### `T close(U)(U other, U maxRelDiff = CommonDefaultFor!(T,U), U maxAbsDiff = 0.0, string file = __FILE__, size_t line = __LINE__);` + +Alias of approxEqual #### `T exist(string file = __FILE__, size_t line = __LINE__);` diff --git a/docs/assets/img/logo-dub.png b/docs/assets/img/logo-dub.png new file mode 100644 index 0000000..4b95461 Binary files /dev/null and b/docs/assets/img/logo-dub.png differ diff --git a/docs/changelog.md b/docs/changelog.md index c9590c5..f9ce724 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,12 @@ layout: default title: Changelog --- +# v0.3.4 + +* Update to DLang frontend 2.91 +* Using std.math.isClose instead of .approxEquals +* Added .close as alias of .approxEquals + # v0.3.3 * .throw must be @trusted, to allow to catch Errors diff --git a/docs/index.md b/docs/index.md index ed85b14..354eede 100644 --- a/docs/index.md +++ b/docs/index.md @@ -62,14 +62,17 @@ assertion. 255.should.equal(10); // Throws an Exception "expected 255 to equal 10" ``` -#### `T approxEqual(U)(U other, U maxRelDiff = 1e-2, U maxAbsDiff = 1e-05, string file = __FILE__, size_t line = __LINE__);` +#### `T approxEqual(U)(U other, U maxRelDiff = CommonDefaultFor!(T,U), U maxAbsDiff = 0.0, string file = __FILE__, size_t line = __LINE__);` -Asserts for aproximated equality of float types. Returns the value wrapped around the -assertion. +Asserts for approximated equality of float types. Returns the value wrapped around the +assertion. See Phobos std.math.isClose(). ```d (1.0f).should.be.approxEqual(1.00000001); -(1.0f).should.not.be.approxEqual(1.001); +(1.0f).should.not.be.approxEqual(1.01); ``` +#### `T close(U)(U other, U maxRelDiff = CommonDefaultFor!(T,U), U maxAbsDiff = 0.0, string file = __FILE__, size_t line = __LINE__);` + +Alias of approxEqual #### `T exist(string file = __FILE__, size_t line = __LINE__);` diff --git a/docs/pijamas.html b/docs/pijamas.html index 99020e2..c5f7161 100644 --- a/docs/pijamas.html +++ b/docs/pijamas.html @@ -755,7 +755,7 @@

Declaration

- @trusted T approxEqual(U = double)(U other, U maxRelDiff = 0.01, U maxAbsDiff = 1e-05, string file = __FILE__, size_t line = __LINE__) if (is(T : real) && __traits(isFloating, T) && is(U : real) && __traits(isFloating, U)); + @trusted T approxEqual(U = double)(U other, U maxRelDiff = CommonDefaultFor!(T, U), U maxAbsDiff = 0.0, string file = __FILE__, size_t line = __LINE__) if (is(T : real) && __traits(isFloating, T) && is(U : real) && __traits(isFloating, U));

@@ -771,6 +771,89 @@

Declaration

+
+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + U other + + +
+

+ Value to compare to compare. +

+
+
+ + U maxRelDiff + + +
+

+ Maximum allowable relative difference. + Setting to 0.0 disables this check. Default depends on the type of + other and the original valie: It is approximately half the number of decimal digits of + precision of the smaller type. +

+
+
+ + U maxAbsDiff + + +
+

+ Maximum absolute difference. This is mainly usefull + for comparing values to zero. Setting to 0.0 disables this check. + Defaults to 0.0. +

+
+
+ + string file + + +
+

+ filename +

+
+
+ + size_t line + + +
+

+ line number inside of file +

+
+
+

Examples

@@ -780,7 +863,7 @@

Examples

  1. double d = 0.1; -double d2 = d + 1e-05; +double d2 = d + 1e-10; d.should.not.be.equal(d2); d.should.be.approxEqual(d2);
  2. @@ -795,6 +878,58 @@

    Examples

+
  • +
    +
    + close +
    +
    +
    +
    +

    Declaration

    +
    +

    + + alias close = approxEqual; + + +

    +
    +
    +
    +
    +
    +
    +
    +

    + Alias to approxEqual + +

    +
    +
    +

    Examples

    +

    + +

    +
    +
    +
      +
    1. double d = 0.1; +double d2 = d + 1e-10; +d.should.not.be.close(d2); +d.should.be.close(d2); +
    2. +
    +
    +
    +
    + +

    +
    +
    + +
    +
  • diff --git a/source/pijamas.d b/source/pijamas.d index dcda78c..b18455a 100644 --- a/source/pijamas.d +++ b/source/pijamas.d @@ -145,11 +145,13 @@ class Assertion(T) * maxAbsDiff = Maximum absolute difference. This is mainly usefull * for comparing values to zero. Setting to 0.0 disables this check. * Defaults to `0.0`. + * file = filename + * line = line number inside of file * * Examples: * ``` * double d = 0.1; - * double d2 = d + 1e-05; + * double d2 = d + 1e-10; * d.should.not.be.equal(d2); * d.should.be.approxEqual(d2); * ``` @@ -163,7 +165,18 @@ class Assertion(T) this.ok(isClose(context, other, maxRelDiff, maxAbsDiff), this.message(other), file, line); return context; } - ///ditto + + /** + * Alias to approxEqual + * + * Examples: + * ``` + * double d = 0.1; + * double d2 = d + 1e-10; + * d.should.not.be.close(d2); + * d.should.be.close(d2); + * ``` + */ alias close = approxEqual; /**