-
Notifications
You must be signed in to change notification settings - Fork 243
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
Either drop cooperative equality or write better tests for it #405
Comments
Make sure to audit the following:
|
I've written ScalaCheck tests at work for a DSL, as well using QuickCheck for verifying Functor laws - https://github.com/kevinmeredith/brentyorgey_upenn_class_hw/blob/master/Typeclassopedia/EvilFunctor.hs. I'd be interested in writing up tests. Could you please tell me where to read more about cooperative equality? I googled for it, but found nothing. |
I'm not sure there is a single article, but cooperative equality refers to the universal def equals(other: Any): Boolean
def hashCode: Int (If you are coming from Haskell this is obviously a somewhat uncomfortable and unfortunate situation, but it's the one we have.) The general thing that Scala tries to achieve with cooperative equality is that you can compare different number types and they will compare equal (and hash to the same value) in most cases (e.g. if both values represent the same signed 32-bit integer). The task here is pretty big since naïvely it means testing the cartesian product of all the types listed (plus Scala's built-in types, e.g. The things we have to ensure:
Does this make sense? |
I believe that I understand what you're looking for. Here's my first commit for adding commutativity tests - kevinmeredith@86c654a.
I'm expecting to write a set of properties, against which all of your above types may be tested. My plan is to finish adding tests for Algebraic. Then, figure out how to write a method that takes a type, i.e. Please let me know if I'm on the right path or not. Thanks |
That sounds good -- one suggestion would be to mention equality in the test name, since we also expect addition, multiplication, etc. to be commutative. |
Haha nevermind, I was misreading the output, you are one step ahead of me. I think this is the right approach. Thanks! |
Thanks for this and continued guidance! I got help on ScalaCheck's mailing list about how to handle multiple implicits - directly use a Then, I updated the For these tests, it showed output that indicates there's not cooperative equality with Double. Note - I should annotate it, but each of the 3 tests that run are:
EDIT - replacing with latest output
When running with Please let me know if, in the above 3 tests, if I'm missing anything. |
Issued #436. For Algebraic and 1-2 other types, using arbitrary This may not be acceptable, but documenting it. |
Hmm, I'm confused why the Travis CI build failed:
I
|
So @rklaehn discovered that
Rational(1, 2) == 0L
(despiteRational(1, 2) != 0
).I'm pretty sure this is a bug in Scala's cooperative equality, but obviously we don't have tests in place to catch this. We need to either have better tests and coverage for this feature, or we should drop cooperative equality.
The text was updated successfully, but these errors were encountered: