From 8700f8cbf5256ae83d0be39719cdf4ebe46ce00c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Panadero=20Guarde=C3=B1o?= Date: Sat, 27 Mar 2021 12:30:48 +0100 Subject: [PATCH 1/3] Moving oldes support version to 2.091 where isClose was introduced to DLang --- .travis.yml | 4 ++-- appveyor.yml | 2 +- dub.json | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index d84a9a1..db0ca94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,12 @@ os: linux -dist: bionic +dist: focal language: d jobs: include: - d: dmd-nightly - d: dmd - - d: dmd-2.090.1 + - d: dmd-2.091.1 - d: ldc allow_failures: - d: dmd-nightly diff --git a/appveyor.yml b/appveyor.yml index 6d96f09..310e4c0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,7 +8,7 @@ environment: DVersion: stable arch: x86 - DC: dmd - DVersion: 2.090.1 + DVersion: 2.091.1 arch: x86 - DC: ldc DVersion: stable diff --git a/dub.json b/dub.json index e18b520..a43704e 100644 --- a/dub.json +++ b/dub.json @@ -37,7 +37,7 @@ } }, "toolchainRequirements": { - "dub": ">=1.19.0", - "frontend": ">=2.090" + "dub": ">=1.20.0", + "frontend": ">=2.091" } } From 13c1e8a3a9c8258f07d1d9997b5ca831884658a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Panadero=20Guarde=C3=B1o?= Date: Sat, 27 Mar 2021 12:59:53 +0100 Subject: [PATCH 2/3] Using math.isClose instead of math.approxEqual --- source/pijamas.d | 48 +++++++++++++++++++++++++++++++++++++++++--- tests/pijamas_spec.d | 24 +++++++++++++++------- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/source/pijamas.d b/source/pijamas.d index f95ef4b..dcda78c 100644 --- a/source/pijamas.d +++ b/source/pijamas.d @@ -103,9 +103,49 @@ class Assertion(T) return context; } + // Ripped from std.math + private template CommonDefaultFor(T,U) + { + import std.traits : CommonType; + import std.algorithm.comparison : min; + + alias baseT = FloatingPointBaseType!T; + alias baseU = FloatingPointBaseType!U; + + enum CommonType!(baseT, baseU) CommonDefaultFor = 10.0L ^^ -((min(baseT.dig, baseU.dig) + 1) / 2 + 1); + } + + private template FloatingPointBaseType(T) + { + import std.traits : isFloatingPoint; + import std.range.primitives : ElementType; + static if (isFloatingPoint!T) + { + alias FloatingPointBaseType = Unqual!T; + } + else static if (isFloatingPoint!(ElementType!(Unqual!T))) + { + alias FloatingPointBaseType = Unqual!(ElementType!(Unqual!T)); + } + else + { + alias FloatingPointBaseType = real; + } + } + /** * Asserts that a float type is aproximated equal. Returns the valued wrapped around the assertion * + * Params: + * other = Value to compare to compare. + * 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. + * maxAbsDiff = Maximum absolute difference. This is mainly usefull + * for comparing values to zero. Setting to 0.0 disables this check. + * Defaults to `0.0`. + * * Examples: * ``` * double d = 0.1; @@ -114,15 +154,17 @@ class Assertion(T) * d.should.be.approxEqual(d2); * ``` */ - T approxEqual(U = double)(U other, U maxRelDiff = 1e-2, U maxAbsDiff = 1e-05, + T approxEqual(U = double)(U other, U maxRelDiff = CommonDefaultFor!(T,U), U maxAbsDiff = 0.0, string file = __FILE__, size_t line = __LINE__) @trusted if (is(T : real) && __traits(isFloating, T) && is(U : real) && __traits(isFloating, U)) { - import std.math : approxEqual; + import std.math : isClose; operator = "be approximated equal than"; - this.ok(approxEqual(context, other, maxRelDiff, maxAbsDiff), this.message(other), file, line); + this.ok(isClose(context, other, maxRelDiff, maxAbsDiff), this.message(other), file, line); return context; } + ///ditto + alias close = approxEqual; /** * Asserts whether a value exists - currently simply compares it with null, if it is a pointer, a class or a string. diff --git a/tests/pijamas_spec.d b/tests/pijamas_spec.d index c6d7fdb..76954d7 100644 --- a/tests/pijamas_spec.d +++ b/tests/pijamas_spec.d @@ -196,14 +196,15 @@ import pijamas; { float f = 0.01; f.should.be.approxEqual(f); - + f.should.be.close(f); + double d = 0.01; d.should.be.approxEqual(d); - + real r = 0.01; r.should.be.approxEqual(r); } - + // it("handles comparing diferent float types") { float f = 0.01; @@ -211,26 +212,35 @@ import pijamas; real r = 0.01; f.should.be.approxEqual(d); f.should.be.approxEqual(r); - + d.should.be.approxEqual(f); d.should.be.approxEqual(r); - + r.should.be.approxEqual(f); r.should.be.approxEqual(d); } // it("asserts that two nearly identical float values are approximated equal") { + float one = 1_000_000_000.0; + one.should.be.close(999_999_999.0); + 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); // and("when increase the difference, it must not be approximated equals") - d2 += 1e-2; + d2 += 1e-5; d.should.not.be.equal(d2); d.should.not.be.approxEqual(d2); assertThrown!Exception(d.should.be.approxEqual(d2)); + + // and("Different default limits for different floating point types") + float oneFloat = 1.0f; + double oneDouble = 1.0; + oneFloat.should.be.close(0.999_99f); + oneDouble.should.not.be.close(0.999_99); } } From bb127a5a225360afe1f60633667a399202ce5023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Panadero=20Guarde=C3=B1o?= Date: Sat, 27 Mar 2021 13:04:17 +0100 Subject: [PATCH 3/3] Documentation updated --- CHANGELOG.md | 6 ++ README.md | 11 ++- docs/assets/img/logo-dub.png | Bin 0 -> 14403 bytes docs/changelog.md | 6 ++ docs/index.md | 11 ++- docs/pijamas.html | 139 ++++++++++++++++++++++++++++++++++- source/pijamas.d | 17 ++++- 7 files changed, 178 insertions(+), 12 deletions(-) create mode 100644 docs/assets/img/logo-dub.png 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 0000000000000000000000000000000000000000..4b954616327e2fa160e8774104d67941ef2af768 GIT binary patch literal 14403 zcmeHtby!sG*8b2TN=ggEkOD&vF-SKGlF~g4J><~cNJ)oCBOxy(ASI_!%2#6BW z68a75dDU}#&-vc#_xt`k%*8c(KhIkCTI*i1_w1RwYPS_G<5S}U0D#L%in1C206OXr z9e|6CdfWFLI{^SlK6q>CA~noBfKD!smNxcqAkxbT4upH!SONf^({uNy+*TSA!xzlD z(gVRnfl%GSM!J|!dsvFEA8oYG-BB$_PQJ-PifR6dLe1gJc0k-IeJj&Vq+V^RcGMb2 z{jB-gy^Wm8HR!Q#K!9)8(YioI(CY-_zc2QAC4$$5QX7^&sFoiCp1^5spZ6x-;z?o!?vZoqp#2we*E?cmm) z)kR(-YX+B1QWxF42+~8pY%{(tS`V#k*aO}#@bSLXf8%t< zm*!MCvvpuuV(5i65EImao^$+eN&LpKBb^DhNcT-4Op~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og --- +# 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; /**