diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c3779a..8485130 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# v0.3.3 + +* .throw must be @trusted, to allow to catch Errors +* Added .biggerOrEqualThan and .smallerOrEqualThan + # v0.3.2 * .equals and others, must be @trusted to allow to call @system opEquals diff --git a/README.md b/README.md index 464bfc6..ef0debe 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,14 @@ Asserts if a value is bigger than another value. Returns the result. 10.should.be.biggerThan(1); ``` +#### `bool biggerOrEqualThan(U)(U other, string file = __FILE__, size_t line = __LINE__);` + +Asserts if a value is bigger or euqal than another value. Returns the result. +```d +10.should.be.biggerOrEqualThan(1); +10.should.be.biggerOrEqualThan(10); +``` + #### `bool smallerThan(U)(U other, string file = __FILE__, size_t line = __LINE__)` Asserts if a value is smaller than another value. Returns the result. @@ -95,6 +103,14 @@ Asserts if a value is smaller than another value. Returns the result. false.should.be.smallerThan(true); ``` +#### `bool smallerOrEqualThan(U)(U other, string file = __FILE__, size_t line = __LINE__)` + +Asserts if a value is smaller or equal than another value. Returns the result. +```d +10.should.be.smallerOrEqualThan(100); +10.should.be.smallerOrEqualThan(10); +``` + #### `U include(U)(U other, string file = __FILE__, size_t line = __LINE__);` Asserts for an input range wrapped around an `Assertion` to contain/include a diff --git a/docs/changelog.md b/docs/changelog.md index 0f3d90e..c9590c5 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,16 @@ layout: default title: Changelog --- +# v0.3.3 + +* .throw must be @trusted, to allow to catch Errors +* Added .biggerOrEqualThan and .smallerOrEqualThan + +# v0.3.2 + +* .equals and others, must be @trusted to allow to call @system opEquals +* .approxEquals to do approximated equality of float types + # v0.3.1 * Make Pijamas @safe diff --git a/docs/index.md b/docs/index.md index e6dae03..ed85b14 100644 --- a/docs/index.md +++ b/docs/index.md @@ -62,6 +62,15 @@ 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__);` + +Asserts for aproximated equality of float types. Returns the value wrapped around the +assertion. +```d +(1.0f).should.be.approxEqual(1.00000001); +(1.0f).should.not.be.approxEqual(1.001); +``` + #### `T exist(string file = __FILE__, size_t line = __LINE__);` Asserts whether a value exists - currently simply compares it with `null`, if it @@ -82,6 +91,14 @@ Asserts if a value is bigger than another value. Returns the result. 10.should.be.biggerThan(1); ``` +#### `bool biggerOrEqualThan(U)(U other, string file = __FILE__, size_t line = __LINE__);` + +Asserts if a value is bigger or euqal than another value. Returns the result. +```d +10.should.be.biggerOrEqualThan(1); +10.should.be.biggerOrEqualThan(10); +``` + #### `bool smallerThan(U)(U other, string file = __FILE__, size_t line = __LINE__)` Asserts if a value is smaller than another value. Returns the result. @@ -90,6 +107,14 @@ Asserts if a value is smaller than another value. Returns the result. false.should.be.smallerThan(true); ``` +#### `bool smallerOrEqualThan(U)(U other, string file = __FILE__, size_t line = __LINE__)` + +Asserts if a value is smaller or equal than another value. Returns the result. +```d +10.should.be.smallerOrEqualThan(100); +10.should.be.smallerOrEqualThan(10); +``` + #### `U include(U)(U other, string file = __FILE__, size_t line = __LINE__);` Asserts for an input range wrapped around an `Assertion` to contain/include a diff --git a/docs/pijamas.html b/docs/pijamas.html index 4226ee2..99020e2 100644 --- a/docs/pijamas.html +++ b/docs/pijamas.html @@ -900,6 +900,57 @@

Examples

+
  • +
    + +
    +
    +
    +

    Declaration

    +
    +

    + + @trusted bool biggerOrEqualThan(U)(U other, string file = __FILE__, size_t line = __LINE__); + + +

    +
    +
    +
    +
    +
    +
    +
    +

    + Asserts if a value is bigger or equal than another value. Returns the result. + +

    +
    +
    +

    Examples

    +

    + +

    +
    +
    +
      +
    1. "z".should.be.biggerOrEqualThan("a"); +10.should.be.biggerOrEqualThan(10); +20.should.be.biggerOrEqualThan(10); +
    2. +
    +
    +
    +
    + +

    +
    +
    + +
    +
  • @@ -950,6 +1001,57 @@

    Examples

    +
  • +
    + +
    +
    +
    +

    Declaration

    +
    +

    + + @trusted bool smallerOrEqualThan(U)(U other, string file = __FILE__, size_t line = __LINE__); + + +

    +
    +
    +
    +
    +
    +
    +
    +

    + Asserts if a value is smaller or euqal than another value. Returns the result. + +

    +
    +
    +

    Examples

    +

    + +

    +
    +
    +
      +
    1. 10.should.be.smallerOrEqualThan(100); +10.should.be.smallerOrEqualThan(10); +false.should.be.smallerOrEqualThan(true); +
    2. +
    +
    +
    +
    + +

    +
    +
    + +
    +
  • @@ -1372,7 +1474,7 @@

    Declaration

    - @safe void Throw(T : Throwable = Exception)(string file = __FILE__, size_t line = __LINE__); + @trusted void Throw(T : Throwable = Exception)(string file = __FILE__, size_t line = __LINE__);

    diff --git a/source/pijamas.d b/source/pijamas.d index 030192f..f95ef4b 100644 --- a/source/pijamas.d +++ b/source/pijamas.d @@ -184,6 +184,22 @@ class Assertion(T) return this.ok(context > other, this.message(other), file, line); } + /** + * Asserts if a value is bigger or equal than another value. Returns the result. + * + * Examples: + * ``` + * "z".should.be.biggerOrEqualThan("a"); + * 10.should.be.biggerOrEqualThan(10); + * 20.should.be.biggerOrEqualThan(10); + * ``` + */ + bool biggerOrEqualThan(U)(U other, string file = __FILE__, size_t line = __LINE__) @trusted + { + operator = "be bigger or equal than"; + return this.ok(context >= other, this.message(other), file, line); + } + /** * Asserts if a value is smaller than another value. Returns the result. * @@ -199,6 +215,22 @@ class Assertion(T) return this.ok(context < other, this.message(other), file, line); } + /** + * Asserts if a value is smaller or euqal than another value. Returns the result. + * + * Examples: + * ``` + * 10.should.be.smallerOrEqualThan(100); + * 10.should.be.smallerOrEqualThan(10); + * false.should.be.smallerOrEqualThan(true); + * ``` + */ + bool smallerOrEqualThan(U)(U other, string file = __FILE__, size_t line = __LINE__) @trusted + { + operator = "be smaller or equal than"; + return this.ok(context <= other, this.message(other), file, line); + } + static if (isForwardRange!T && __traits(compiles, context.isSorted)) { /** diff --git a/tests/pijamas_spec.d b/tests/pijamas_spec.d index 9eac302..c6d7fdb 100644 --- a/tests/pijamas_spec.d +++ b/tests/pijamas_spec.d @@ -415,6 +415,9 @@ import pijamas; a2.should.be.biggerThan("aaa"); a2.should.not.be.biggerThan("zz"); assertThrown!Exception(a2.should.be.biggerThan("zz")); + + 10.should.be.biggerOrEqualThan(10); + 50.should.be.biggerOrEqualThan(10); } } @@ -431,5 +434,8 @@ import pijamas; a2.should.be.smallerThan(2000); a2.should.be.not.smallerThan(99); assertThrown!Exception(a2.should.be.smallerThan(99)); + + 10.should.be.smallerOrEqualThan(10); + 10.should.be.smallerOrEqualThan(50); } }