assertables 8.14.0

Assertables: assert macros for better testing, debugging, quality assurance, and runtime reliability.
Documentation
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Assert a number is within epsilon of another number."><title>lib::assert_in_epsilon - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-c5d6553a23f1e5a6.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="lib" data-themes="" data-resource-suffix="" data-rustdoc-version="1.81.0 (eeb90cda1 2024-09-04)" data-channel="1.81.0" data-search-js="search-d234aafac6c221dd.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-d2fab2bf619172d3.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-df360f571f6edeae.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../lib/index.html">lib</a></h2></div><h2 class="location"><a href="#">Module assert_in_epsilon</a></h2><div class="sidebar-elems"><h2><a href="../index.html">In crate lib</a></h2></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Module <a href="../index.html">lib</a>::<wbr><a class="mod" href="#">assert_in_epsilon</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><a class="src" href="../../src/lib/assert_in_epsilon.rs.html#1-304">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Assert a number is within epsilon of another number.</p>
<p>Pseudocode:<br>
| a - b | ≤ ε * min(a, b)</p>
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>assertables::<span class="kw-2">*</span>;
<span class="kw">let </span>a: i8 = <span class="number">10</span>;
<span class="kw">let </span>b: i8 = <span class="number">20</span>;
<span class="kw">let </span>epsilon: i8 = <span class="number">1</span>;
<span class="macro">assert_in_epsilon!</span>(a, b, epsilon);</code></pre></div>
<h3 id="comparisons"><a class="doc-anchor" href="#comparisons">§</a>Comparisons</h3>
<p>This crate provides macro groups that test approximations and nearness:</p>
<ul>
<li>
<p><a href="../macro.assert_approx_eq.html" title="macro lib::assert_approx_eq"><code>assert_approx_eq</code></a> and
<a href="../macro.assert_approx_ne.html" title="macro lib::assert_approx_ne"><code>assert_approx_ne</code></a> test the approximate
equality within 1e-6. The macro name and the approximate value are chosen
to be similar to the longtime popular rust crate <code>assert_approx_eq</code>.</p>
</li>
<li>
<p><a href="../macro.assert_in_delta.html" title="macro lib::assert_in_delta"><code>assert_in_delta</code></a> tests the absolute error
(i.e. delta). This is the magnitude of the difference between the exact
value and the approximation.</p>
</li>
<li>
<p><a href="../macro.assert_in_epsilon.html" title="macro lib::assert_in_epsilon"><code>assert_in_epsilon</code></a> tests the relative
error (i.e. epsilon). This is the absolute error divided by the magnitude
of the exact value. This can be used to compare approximations of numbers
of wildly differing size.</p>
</li>
</ul>
<p>Examples:</p>
<ul>
<li>
<p>Approximating the number 100 and 103 has an absolute error (delta) of 3
and a relative error (epsilon) of 0.03.</p>
</li>
<li>
<p>Approximating the number 1,000,000 and 1,000,003 has an absolute error
(delta) of 3, and a relative error (espilon) of 0.000003.</p>
</li>
<li>
<p>For many kinds of applications, the relative error is more important than
the absolute error.</p>
</li>
</ul>
<h3 id="thanks"><a class="doc-anchor" href="#thanks">§</a>Thanks</h3>
<ul>
<li>
<p>Thanks to <a href="https://github.com/ashleygwilliams">Ashley Williams</a> for
creating and maintaining the <code>assert_approx_eq</code> crate.</p>
</li>
<li>
<p>Thanks to <a href="https://github.com/zenspider">Ryan Davis</a> and Ruby minitest for
creating and maintaining <code>assert_in_delta</code> and <code>assert_in_epsilon</code> code.</p>
</li>
</ul>
<h2 id="module-macros"><a class="doc-anchor" href="#module-macros">§</a>Module macros</h2>
<ul>
<li><a href="../macro.assert_in_epsilon.html" title="macro lib::assert_in_epsilon"><code>assert_in_epsilon</code></a></li>
<li><a href="../macro.assert_in_epsilon_as_result.html" title="macro lib::assert_in_epsilon_as_result"><code>assert_in_epsilon_as_result</code></a></li>
<li><a href="../macro.debug_assert_in_epsilon.html" title="macro lib::debug_assert_in_epsilon"><code>debug_assert_in_epsilon</code></a></li>
</ul>
</div></details></section></div></main></body></html>