JavaHamcrest
JavaHamcrest copied to clipboard
Add FloatIsCloseTo matcher
- Add
FloatIsCloseTomatcher as copy ofIsCloseTomatcher - Rename
IsCloseTomatcher toDoubleIsCloseTo - Change error message for excluding errors in additional floating calculations (May user catch this error even with doubles?)
- Ignore eclipse specific files
PS. Example of error with additional floating calculations:
public static void main(String[] args) {
System.out.println(abs(1.0f - 0.1f) - 0.5f);
System.out.println(abs(1.0d - 0.1d) - 0.5d);
}
After run:
0.39999998
0.4
Thanks for contributing. I have a couple of points. First, what problem are you trying to solve, what is the motivation for this change? Secondly, this would be a breaking change for existing users of IsCloseTo.
First, what problem are you trying to solve, what is the motivation for this change?
There's no closeTo matcher for float value (only with casting to double).
Secondly, this would be a breaking change for existing users of IsCloseTo.
I can rename DoubleIsCloseTo -> IsCloseTo. I tried resolve issue with single IsCloseTo and generics, but that solution doesn't work.
Sorry, to be clearer, is this just a matter of inconvenience, or is there a real problem? Are you seeing significant differences in the results when casting floats to doubles?
Are you seeing significant differences in the results when casting floats to doubles?
No, I don't. I think there may be problem. And of course there'r ugly type cast in strong type system.
@laz2 i personally prefer using the Matchers directly like Is.is instead of just referring to CoreMatchers.is. like microservices instead of monoliths, instead of one IsCloseTo to rule them all, creating FloatIsCloseTo and DoubleIsCloseTo makes more sense, also you might want to enforce Float or Double and not want auto boxing or type conversion.
please can you rebase from master, as hamcrest-core and hamcrest-library have been refactored a lot and also deprecated, so that everything is just in hamcrest.
A long time ago, I had a plan to extract related matchers into a set of common DSL types, which I think might work here. Double and Float is probably one of the few occasions where a static import doesn't work.
Going to try and kick start hamcrest, so if you want to get it merged, please rebase from the branch v2.3-candidates.
Still trying to understand how has permissions to perform a release.
Done in another pull request #385