Re: [Haskell-cafe] ANN: LeanCheck v0.9.0 -- enumerative property testing

Yes, leancheck is awesome.
When should I reach to enumerative testing?
I think enumerative testing is best suited to algebraic data types. https://mail.haskell.org/pipermail/haskell-cafe/2018-September/129951.html In the past I had one standard example where random enumeration seems better than enumerative: (non)associativity of floating point ops (I like to use this in teaching) That's immediate in Quickcheck quickCheck $ \ x y z -> (x::Double) + (y+z) == (x+y)+z *** Failed! Falsifiable (after 3 tests and 3 shrinks): -0.3 -1.4266097805446862 -1.2543117889178947 You don't get to see a counterexample in Smallcheck Prelude Test.SmallCheck> smallCheck 5 $ \ x y z -> (x::Double) + (y+z) == (x+y)+z Completed 50653 tests without failure. To my surprise, we now have Prelude Test.LeanCheck> check $ \ x y z -> (x::Double) + (y+z) == (x+y)+z *** Failed! Falsifiable (after 87 tests): 0.0 Infinity (-Infinity) and I get the above (with "real" numbers) via Prelude Test.LeanCheck> checkFor 1000 $ \ x y z -> isInfinite x || isInfinite y || isInfinite z || (x::Double) + (y+z) == (x+y)+z *** Failed! Falsifiable (after 306 tests): 1.0 1.0 0.3333333333333333 Turns out the enumeration in Leancheck uses Rationals, while Smallcheck uses encodeFloat, which happens to produce only "nice" numbers (very few bits set) in the beginning. Prelude Test.LeanCheck> list 3 series :: [Double] [0.0,1.0,-1.0,2.0,0.5,-2.0,4.0,0.25,-0.5,-4.0,-0.25] Prelude Test.LeanCheck> take 12 $ list :: [Double] [0.0,1.0,-1.0,Infinity,0.5,2.0,-Infinity,-0.5,-2.0,0.3333333333333333,3.0,-0.3333333333333333] - J.W. PS: this post wouldn't be complete without me complaining that I cannot (easily) put the type annotation where it belongs - in the declaration of the name: Prelude Test.LeanCheck> check $ \ (x::Double) y z -> x + (y+z) == (x+y)+z <interactive>:22:12: error: Illegal type signature: ‘Double’ Type signatures are only allowed in patterns with ScopedTypeVariables Wat? TypeVariables? There aren't any!

Sorry - I copy-pasted the prompt wrongly. This is actually using Smallcheck:
Prelude Test.LeanCheck> list 3 series :: [Double] [0.0,1.0,-1.0,2.0,0.5,-2.0,4.0,0.25,-0.5,-4.0,-0.25]
and this is Leancheck:
Prelude Test.LeanCheck> take 12 $ list :: [Double] [0.0,1.0,-1.0,Infinity,0.5,2.0,-Infinity,-0.5,-2.0,0.3333333333333333,3.0,-0.3333333333333333]

On Thu, Jan 17, 2019 at 06:28:32PM +0100, Johannes Waldmann wrote:
Prelude Test.LeanCheck> checkFor 1000 $ \ x y z -> isInfinite x || isInfinite y || isInfinite z || (x::Double) + (y+z) == (x+y)+z *** Failed! Falsifiable (after 306 tests): 1.0 1.0 0.3333333333333333
Turns out the enumeration in Leancheck uses Rationals, while Smallcheck uses encodeFloat, which happens to produce only "nice" numbers (very few bits set) in the beginning.
I improved the LeanCheck floating enumeration starting with v0.8.0 to catch exactly this kind of error. :-)
PS: this post wouldn't be complete without me complaining that I cannot (easily) put the type annotation where it belongs - in the declaration of the name:
Prelude Test.LeanCheck> check $ \ (x::Double) y z -> x + (y+z) == (x+y)+z
<interactive>:22:12: error: Illegal type signature: ‘Double’ Type signatures are only allowed in patterns with ScopedTypeVariables
Wat? TypeVariables? There aren't any!
You can get the above to parse by passing `-XScopedTypeVariables` to GHC: $ ghci -XScopedTypeVariables > import Test.LeanCheck > check $ \(x::Double) y z -> x + (y+z) == (x+y) + z *** Failed! Falsifiable (after 87 tests): 0.0 Infinity (-Infinity)

I think they're complaining about the name of the extension. Years ago, it
was a separate extension, but it got folded into ScopedTypeVariables.
On Thu, Jan 17, 2019 at 8:01 PM Rudy Matela
On Thu, Jan 17, 2019 at 06:28:32PM +0100, Johannes Waldmann wrote:
Prelude Test.LeanCheck> checkFor 1000 $ \ x y z -> isInfinite x || isInfinite y || isInfinite z || (x::Double) + (y+z) == (x+y)+z *** Failed! Falsifiable (after 306 tests): 1.0 1.0 0.3333333333333333
Turns out the enumeration in Leancheck uses Rationals, while Smallcheck uses encodeFloat, which happens to produce only “nice” numbers (very few bits set) in the beginning.
I improved the LeanCheck floating enumeration starting with v0.8.0 to catch exactly this kind of error. :-)
PS: this post wouldn’t be complete without me complaining that I cannot (easily) put the type annotation where it belongs - in the declaration of the name:
Prelude Test.LeanCheck> check $ \ (x::Double) y z -> x + (y+z) == (x+y)+z
:22:12: error: Illegal type signature: ‘Double’ Type signatures are only allowed in patterns with ScopedTypeVariables
Wat? TypeVariables? There aren’t any!
You can get the above to parse by passing -XScopedTypeVariables to GHC:
$ ghci -XScopedTypeVariables
import Test.LeanCheck check $ \(x::Double) y z -> x + (y+z) == (x+y) + z *** Failed! Falsifiable (after 87 tests): 0.0 Infinity (-Infinity)
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com

On 1/18/19 2:36 AM, Brandon Allbery wrote:
I think they're complaining about the name of the extension.
Yes. And hat I need to use an extension at all - to be allowed to annotate the declaration of an identifier with its type. Of course it's easy to work around, but I think it does not look good, especially when teaching. - J.

Hi, Am Donnerstag, den 17.01.2019, 18:28 +0100 schrieb Johannes Waldmann:
<interactive>:22:12: error: Illegal type signature: ‘Double’ Type signatures are only allowed in patterns with ScopedTypeVariables
Wat? TypeVariables? There aren't any!
I feel your pain: https://github.com/ghc-proposals/ghc-proposals/pull/119 Let’s hope we get Haskell2x somewhen, including (at least) PatternSignatures, or even all of ScopedTypeVariables. Interestingly, my proposal cites a rant from you from 10 years ago: https://mail.haskell.org/pipermail/haskell-cafe/2009-April/059519.html :-) Cheers, Joachim -- Joachim Breitner mail@joachim-breitner.de http://www.joachim-breitner.de/

Leancheck looks great! Could you also please compare it to feat? That's
what I've been using for enumerating algebraic datatypes by size (vs depth)
so far.
On Fri, Jan 18, 2019, 16:22 Joachim Breitner Hi, Am Donnerstag, den 17.01.2019, 18:28 +0100 schrieb Johannes Waldmann: <interactive>:22:12: error:
Illegal type signature: ‘Double’
Type signatures are only allowed in patterns with
ScopedTypeVariables Wat? TypeVariables? There aren't any! I feel your pain:
https://github.com/ghc-proposals/ghc-proposals/pull/119 Let’s hope we get Haskell2x somewhen, including (at least)
PatternSignatures, or even all of ScopedTypeVariables. Interestingly, my proposal cites a rant from you from 10 years ago:
https://mail.haskell.org/pipermail/haskell-cafe/2009-April/059519.html
:-) Cheers,
Joachim --
Joachim Breitner
mail@joachim-breitner.de
http://www.joachim-breitner.de/ _______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
participants (5)
-
Brandon Allbery
-
Joachim Breitner
-
Johannes Waldmann
-
Paul Brauner
-
Rudy Matela