New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Override PartialEq
derives when a approx-partial-eq
feature flag is enabled.
#1085
Comments
PartialEq
derives when approx
feature flag is enabled.PartialEq
derives when a approx-partial-eq
feature flag is enabled.
I don't think we should change PartialEq to be approximate, because I think this would surprise lots of people. Instead, have you seen our usage of approx? There's probably some unit tests within our own repos that aren't yet using approx, but they should be if you feel like contributing. |
Maybe I'm being a bit misunderstood. Take this struct for example: pub struct AddressSearch {
id: Id,
address_string: String,
postal_info: Option<PostalInfoReference>,
geometry: Point,
} How would you go about unit testing equality of an expected value to an REST API call? Do I really want to check the equality of each and every field? What happens then when A temporary solution that I'm currently using is manually implementing impl PartialEq for AddressSearch {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
&& self.address_string == other.address_string
&& self.postal_info == other.postal_info
&& approx::relative_eq!(self.geometry, other.geometry, epsilon = 1e-6)
}
} Being able to override Overriding |
Yeah, floating point makes comparisons annoying. It's not so much conceptually difficult, but it makes writing test code very verbose which is a pain. But people assume a contract with If you want to be able to approximately compare your structs, I'd recommend implementing the |
Mostly a feature request that I'm interested in hearing your take on. It's quite common for me to have failed unit tests that check
assert_eq!
on structs with geometries, simply because of floating point rounding errors.The text was updated successfully, but these errors were encountered: