# A question about GHC test coverage Classic List Threaded 4 messages Open this post in threaded view
|

## A question about GHC test coverage

 You should not have to write tests for functions you did not define. Correct me if I'm wrong, but any property of max can be derived from the properties of <=. Sadly, the laws for Ord are not stated in the documentation of Data.Ord. (Because there is no consensus?) They are: Reflexive: if x == y then x <= y Transitive: if x <= y and y <= z then x <= z Antisymmetric: if x <= y and y <= x then x == y Olaf _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafeOnly members subscribed via the mailman list are allowed to post.
Open this post in threaded view
|

## Re: A question about GHC test coverage

 On 15/02/17 10:35 AM, Olaf Klinke wrote: > You should not have to write tests for functions you did not define. Correct me if I'm wrong, but any property of max can be derived from the properties of <=. Unfortunately, this isn't quite true. Suppose we have two values x y such that x <= y && y <= x && x == y *BUT* x and y are distinguishable some other way.  For example, suppose we are modelling rational numbers by pairs (n,d) *without* insisting that gcd(n,d) == 0.  Then we have     (n1,d1) == (n2,d2) = n1*d2 == n2*d1     compare (n1,d1) (n2,d2) = compare (n1*d2) (n2*d1) BUT (1,2) and (2,4), while ==, are none-the-less distinguishable. Now ask about max x y.  If we have      max a b = if a > b then a else b then max x y delivers y.  But if we have      max a b = if a < b then b else a then max x y delivers x, and these two results can be distinguished. I know and freely admit that if I want a version of max that satisfies stronger conditions than Ord can guarantee, it is up to me to write it. So you could say that the bug was that I *should* have written my own max, and didn't.  But that's basically my point. (For an example of two values that can't be distinguished by compare or ==, consider -0.0 and +0.0.  If I give those to max, what do I get back?  No, that wasn't the test case I needed.) _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafeOnly members subscribed via the mailman list are allowed to post.