approx
.
.
Collection of the latest Issues
gsnedders
Currently, the output is indistinguishable from assert_eq!
's:
It would be nicer to give allowable ranges for both left/right based on the variance allowed.
brendanzab
Seeing as this repository seems to be getting some love now (thank you to @sebcrozet in particular!!), I'm wondering if it would be a good idea to transfer it to a more appropriate org? I don't really have the time or energy to maintain it myself, but I feel bad stealing the clout.
obsgolem
This library appears to be the de-facto standard for approximate comparisons. Downstreams include ndarray and nalgebra. I just ran into an issue where ndarray is using an older version tied to an older version of num-complex. If you aren't planning on making breaking changes then it would be nice if you could bump to a 1.0 version so that feature additions don't require upstreams to bump their versions.
dsroche
Consider this small example:
Note that x
and y
are normal, full-precision floating-point values (not "subnormals"), above the epsilon
threshold, and their relative error is (x - y)/x, which equals 0.01, far above the default threshold. However, they are marked as "relatively equal" in the current implementation.
The problem is in the logic of the provided implementation of RelativeEq::relative_eq()
for f32
and f64
, namely these lines:
While the precise definition of relative equality and the parameters epsilon
and max_relative
are never clearly specified in the documentation, based on the referenced blog posts, it seems that the intention is to use epsilon
as a zero-closeness threshold, and max_relative
as the relative error threshold.
The issue stems from not checking the two input numbers (self
and other
in this case) individually against epsilon
for a zero-threshold, but instead testing their absolute difference against epsilon
. As a result, relative equality works as expected for large numbers, but in practice defaults to absolute-difference equality for values less than 1.
bluenote10
In data science use cases, the most frequent test is to assert approximate equality of entire float data vectors. For instance in Numpy based code, testing with assert_allclose
is ubiquitous. I'm looking for the equivalent in Rust.
As far as I can see, the macros currently doesn't support slices. Is there an interest to support them?
JP-Ellis
The documentation currently is not very clear as to how it computes things, and one reason I think is that nearly all the example just compare whether 1.0
is approximately equal to 1.0
which isn't very illustrative.
It would be good if there were examples at the crate level showing the differences between the various macros that illustrate when one should use abs_diff_eq!
vs relative_eq!
vs ulps_eq!
. Additionally, the documentation for each macro is quite lacking (e.g. assert_relative_eq
and relative_eq
are not very helpful).
It is also unclear from the documentation what keyword arguments are allowed in which macros. Are the crate-level examples exhaustive ? Or can I also use max_relative
in the ulps_eq!
macro? Does the order matter? Because the examples show both:
What if I want to assert that two results should have "x
decimal digits in common", is this possible?
pcpthm
Expected behavior: Runs fine.
Actual behavior: thread 'main' panicked at 'attempt to subtract with overflow'
.
arekfu
It would be great to extend the assert_*
macros to accept a custom panic message, the way assert_eq!
does:
assert_eq!(a, b, "Failed to compare a and b; a={}, b={}", a, b);
vandenheuvel
Is there any outlook on automatic derivations of the traits in this crate?
I tried to write a derive crate, but got stuck. Deriving for example AbsDiffEq
for structs could be done by calling AbsDiffEq::abs_diff_eq
on all fields, in combination with an impl<T: Eq> AbsDiffEq for T
. This last trait implementation collides however with the existing derivation implementations such as impl<'a, T: AbsDiffEq> AbsDiffEq for &'a T
. I don't know how to solve this problem without removing these trait derivations, or until this work is finished.
michael-p
It would be great to have debug_assert_{relative|ne}_{eq|ne}
macros that are only checked in non optimized builds, similar to debug_assert!
from the standard library.
Implementation should be straightforward, something like:
brendanzab
As @Andlon explains:
I'm not sure if it's actually wise to provide a default epsilon/tolerance - this is the very problem that Bruce Dawson discusses in the randomascii blog I know we've both spent some time reading. The problem with absolute differences is that there is really no sensible default - it depends entirely on the numbers you are comparing.
brendanzab
At the moment we have:
ApproxEq::Epsilon
epsilon
max_relative
max_ulps
But I'm not sure how descriptive these are. Any other ideas? I'm also wondering if the type of max_ulps
should be associated...
Related: https://github.com/brendanzab/approx/issues/8#issuecomment-296958843
WaDelma
Currently only f32
and f64
are implemented.
(T, ..)
[T]
RefCell<T>
Cell<T>
[T; n]
(up to 32
)emberian
This issue was automatically generated. Feel free to close without ceremony if
you do not agree with re-licensing or if it is not possible for other reasons.
Respond to @cmr with any questions or concerns, or pop over to
#rust-offtopic
on IRC to discuss.
You're receiving this because someone (perhaps the project maintainer) published a crates.io package with the license as "MIT" xor "Apache-2.0" and the repository field pointing here.
TL;DR the Rust ecosystem is largely Apache-2.0. Being available under that license is good for interoperation. The MIT license as an add-on can be nice for GPLv2 projects to use your code.
The MIT license requires reproducing countless copies of the same copyright header with different names in the copyright field, for every MIT library in use. The Apache license does not have this drawback. However, this is not the primary motivation for me creating these issues. The Apache license also has protections from patent trolls and an explicit contribution licensing clause. However, the Apache license is incompatible with GPLv2. This is why Rust is dual-licensed as MIT/Apache (the "primary" license being Apache, MIT only for GPLv2 compat), and doing so would be wise for this project. This also makes this crate suitable for inclusion and unrestricted sharing in the Rust standard distribution and other projects using dual MIT/Apache, such as my personal ulterior motive, the Robigalia project.
Some ask, "Does this really apply to binary redistributions? Does MIT really require reproducing the whole thing?" I'm not a lawyer, and I can't give legal advice, but some Google Android apps include open source attributions using this interpretation. Others also agree with it. But, again, the copyright notice redistribution is not the primary motivation for the dual-licensing. It's stronger protections to licensees and better interoperation with the wider Rust ecosystem.
To do this, get explicit approval from each contributor of copyrightable work (as not all contributions qualify for copyright, due to not being a "creative work", e.g. a typo fix) and then add the following to your README:
and in your license headers, if you have them, use the following boilerplate (based on that used in Rust):
It's commonly asked whether license headers are required. I'm not comfortable making an official recommendation either way, but the Apache license recommends it in their appendix on how to use the license.
Be sure to add the relevant LICENSE-{MIT,APACHE}
files. You can copy these
from the Rust repo for a plain-text
version.
And don't forget to update the license
metadata in your Cargo.toml
to:
I'll be going through projects which agree to be relicensed and have approval by the necessary contributors and doing this changes, so feel free to leave the heavy lifting to me!
To agree to relicensing, comment with :
Or, if you're a contributor, you can check the box in this repo next to your name. My scripts will pick this exact phrase up and check your checkbox, but I'll come through and manually review this issue later as well.
122
utest standard testing for Rust
Make sure your not using this for testing no_std code as it relies on the unstable branch
239
Shuttle is a library for testing concurrent Rust code
It is an implementation of a number of
323
Let's make a web service and client in Rust
So I'm working on this project Rust regression testing
329
HTTP mocking to test Rust applications
wiremock provides HTTP mocking to perform black-box testing of Rust applications that
16
Grillon offers an elegant and natural way to approach end-to-end HTTP API testing in Rust
Elegant, intuitive and expressive API
18
Testing framework for rust which enhances the built-in library with some useful features
Net unit-testing framework documentation