Skip to content

Commit

Permalink
Documentation updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Zardoz89 committed Mar 27, 2021
1 parent 13c1e8a commit bb127a5
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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__);`

Expand Down
Binary file added docs/assets/img/logo-dub.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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__);`

Expand Down
139 changes: 137 additions & 2 deletions docs/pijamas.html
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ <h4>Declaration</h4>
<div class="dlang">
<p class="para">
<code class="code">
<span class="ddoc_anchor" id="Assertion.approxEqual"></span>@trusted T <code class="code">approxEqual</code>(U = double)(U <code class="code">other</code>, U <code class="code">maxRelDiff</code> = 0.01, U <code class="code">maxAbsDiff</code> = 1e-05, string <code class="code">file</code> = __FILE__, size_t <code class="code">line</code> = __LINE__) if (is(T : real) &amp;&amp; __traits(isFloating, T) &amp;&amp; is(U : real) &amp;&amp; __traits(isFloating, U));
<span class="ddoc_anchor" id="Assertion.approxEqual"></span>@trusted T <code class="code">approxEqual</code>(U = double)(U <code class="code">other</code>, U <code class="code">maxRelDiff</code> = CommonDefaultFor!(T, U), U <code class="code">maxAbsDiff</code> = 0.0, string <code class="code">file</code> = __FILE__, size_t <code class="code">line</code> = __LINE__) if (is(T : real) &amp;&amp; __traits(isFloating, T) &amp;&amp; is(U : real) &amp;&amp; __traits(isFloating, U));

</code>
</p>
Expand All @@ -771,6 +771,89 @@ <h4>Declaration</h4>

</p>
</div>
<div class="ddoc_params">
<h4>Parameters</h4>
<table cellspacing="0" cellpadding="5" border="0" class="graybox">
<tbody>
<tr class="ddoc_param_row">
<td scope="ddoc_param_id">
<code class="code">
<em class="term">U <code class="code">other</code></em>
</code>
</td>
<td>
<div class="ddoc_param_desc">
<p class="para">
Value to compare to compare.
</p>
</div>
</td>
</tr>
<tr class="ddoc_param_row">
<td scope="ddoc_param_id">
<code class="code">
<em class="term">U <code class="code">maxRelDiff</code></em>
</code>
</td>
<td>
<div class="ddoc_param_desc">
<p class="para">
Maximum allowable relative difference.
Setting to 0.0 disables this check. Default depends on the type of
<code class="code"><code class="code">other</code></code> and the original valie: It is approximately half the number of decimal digits of
precision of the smaller type.
</p>
</div>
</td>
</tr>
<tr class="ddoc_param_row">
<td scope="ddoc_param_id">
<code class="code">
<em class="term">U <code class="code">maxAbsDiff</code></em>
</code>
</td>
<td>
<div class="ddoc_param_desc">
<p class="para">
Maximum absolute difference. This is mainly usefull
for comparing values to zero. Setting to 0.0 disables this check.
Defaults to <code class="code">0.0</code>.
</p>
</div>
</td>
</tr>
<tr class="ddoc_param_row">
<td scope="ddoc_param_id">
<code class="code">
<em class="term">string <code class="code">file</code></em>
</code>
</td>
<td>
<div class="ddoc_param_desc">
<p class="para">
filename
</p>
</div>
</td>
</tr>
<tr class="ddoc_param_row">
<td scope="ddoc_param_id">
<code class="code">
<em class="term">size_t <code class="code">line</code></em>
</code>
</td>
<td>
<div class="ddoc_param_desc">
<p class="para">
<code class="code">line</code> number inside of <code class="code">file</code>
</p>
</div>
</td>
</tr>

</tbody>
</table>
</div>
<div class="ddoc_examples">
<h4>Examples</h4>
<p class="para">
Expand All @@ -780,7 +863,7 @@ <h4>Examples</h4>
<div class="dlang">
<ol class="code_lines">
<li><code class="code"><span class="keyword">double</span> d = 0.1;
<span class="keyword">double</span> d2 = d + 1e-05;
<span class="keyword">double</span> d2 = d + 1e-10;
d.should.not.be.equal(d2);
d.should.be.<span class="psymbol">approxEqual</span>(d2);
</code></li>
Expand All @@ -795,6 +878,58 @@ <h4>Examples</h4>

</div>

</li><li class="ddoc_member">
<div class="ddoc_member_header">
<div class="ddoc_header_anchor">
<a href="#Assertion.close" id="Assertion.close"><code class="code">close</code></a>
</div>
</div><div class="ddoc_decl">
<section class="section">
<div class="declaration">
<h4>Declaration</h4>
<div class="dlang">
<p class="para">
<code class="code">
<span class="ddoc_anchor" id="Assertion.close"></span>alias <code class="code">close</code> = approxEqual;

</code>
</p>
</div>
</div>
</section>
</div>
<div class="ddoc_decl">
<section class="section ddoc_sections">
<div class="ddoc_summary">
<p class="para">
Alias to approxEqual

</p>
</div>
<div class="ddoc_examples">
<h4>Examples</h4>
<p class="para">

<section class="code_listing">
<div class="code_sample">
<div class="dlang">
<ol class="code_lines">
<li><code class="code"><span class="keyword">double</span> d = 0.1;
<span class="keyword">double</span> d2 = d + 1e-10;
d.should.not.be.<span class="psymbol">close</span>(d2);
d.should.be.<span class="psymbol">close</span>(d2);
</code></li>
</ol>
</div>
</div>
</section>

</p>
</div>
</section>

</div>

</li><li class="ddoc_member">
<div class="ddoc_member_header">
<div class="ddoc_header_anchor">
Expand Down
17 changes: 15 additions & 2 deletions source/pijamas.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
* ```
Expand All @@ -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;

/**
Expand Down

0 comments on commit bb127a5

Please sign in to comment.