News for hackers. Stuff that matters.
Re:Using Haskell's QuickCheck for Python by toolslive on Saturday March 21, 2015 @03:23AM (#9242091)
I have seen people do the same with their C code: code it up in C, expose it using the ffi and use quickcheck to exercise it. It's not only Haskell that can be used this way. OCaml + ctypes is also an option.
Re:Using Haskell's QuickCheck for Python by sa2ajj on Saturday March 21, 2015 @09:08AM (#9242640)
I remember on one of the Erlang User Conferences there was an [impressive] presentation of testing C code with an erlang "driver".
Re:Using Haskell's QuickCheck for Python by rusbus on Saturday March 21, 2015 @01:26AM (#9241942)
Or of course, you can skip haskell and just use the python port https://pypi.python.org/pypi/pytest-quickcheck
Re:Using Haskell's QuickCheck for Python by sa2ajj on Saturday March 21, 2015 @02:23AM (#9242007)
It seems to provide random data generation only.

I'd say _the_ feature of QuickCheck is minimisation of the counter example.

Re:Using Haskell's QuickCheck for Python by DRMacIver on Saturday March 21, 2015 @03:55AM (#9242144)
Yep. This is why I wrote Hypothesis: http://hypothesis.readthedocs.org/ / https://pypi.python.org/pypi/hypothesis

It's a lot more fully featured than the alternatives. It still lacks a few features of quickcheck (coarbitrary for function generation, labelling of examples), but it does example minimization and a whole bunch of things even quickcheck doesn't.

Re:Using Haskell's QuickCheck for Python by teh on Saturday March 21, 2015 @06:58AM (#9242394)
Hypothesis looks fantastic. A friend of mine and me spent a while on Google collecting Python QC implementations but didn't find any that implemented shrinking.

Hypothesis escaped our search. I don't know how but the project could do with better Google ranking :)

It has some really useful features like storing the counterexamples.

The CLA is a bit odd but I'm sure you have good reasons!

Re:Using Haskell's QuickCheck for Python by DRMacIver on Saturday March 21, 2015 @07:47AM (#9242481)
Yeah, the google ranking of Hypothesis when you search for python quickcheck is a thing that's been bugging me. There's a blog post from 2013 about it on the front page but none of the various places the project exists appear. I'm not sure what to do about it. I'm planning to do a bunch of shopping around and promoting of the library when the 1.0 release happpens (probably next week), so hopefully that should help.

The CLA is for a mix of weird personal reasons around open source and cynically practical ones. Hypothesis is 100% always going to remain free, but I'm trying to figure out ways that I can make money out of working on it (I've put a ton of work into it, so it would be a shame not to) and that's a lot easier if I retain the copyright. I may decide it's not useful and drop it later, but it's a lot easier to have it now and drop it later than it is to try and retroactively get one if it turns out I need it.

Re:Using Haskell's QuickCheck for Python by DRMacIver on Saturday March 21, 2015 @04:13AM (#9242161)
Realised I should have linked to http://hypothesis.readthedocs.org/en/master/internals.html to back up that "a whole bunch of things even quickcheck doesn't" claim. :-)
Re:Using Haskell's QuickCheck for Python by sa2ajj on Saturday March 21, 2015 @09:07AM (#9242638)
Thank you for bringing it in: I've been looking for a pure Python analogue of QuickCheck.
Re:Using Haskell's QuickCheck for Python by cpa on Saturday March 21, 2015 @05:31AM (#9242251)
Neat, but there's a subtelty: at the end of the article, we only proved that square is error-free[0] when given an Int as input (because the haskell version of square is Int -> IO Int). But Python being loosely typed, I could call square on a float, and in this case nothing can be said of the python function.

Also, you have to make sure haskell's Ints and Python's Int are the same on your platform (one could be 32 bits and the other 64 bits).

[0] we did not prove anything, but just ran a bunch of tests, but you get the point.

Re:Using Haskell's QuickCheck for Python by Ded7xSEoPKYNsDd on Saturday March 21, 2015 @07:03AM (#9242399)
> Also, you have to make sure haskell's Ints and Python's Int are the same on your platform (one could be 32 bits and the other 64 bits).

Aren't they both infinite-resolution?

Re:Using Haskell's QuickCheck for Python by DRMacIver on Saturday March 21, 2015 @07:39AM (#9242471)
No, the infinite precision integer type in Haskell is called Integer. Int is a platform dependent fixed size int.
Re:Using Haskell's QuickCheck for Python by bensummers on Saturday March 21, 2015 @03:38AM (#9242115)
You might also want to have a look at hypothesis:

https://github.com/DRMacIver/hypothesis

http://hypothesis.readthedocs.org/en/master/

It's a QuickCheck inspired python testing library with some interesting new ideas.

Re:Using Haskell's QuickCheck for Python by codelion on Saturday March 21, 2015 @07:21AM (#9242432)
Neat trick using the FFI for this. Also, quickCheck like libraries are available in other languages e.g JUnit-QuickCheck for Java - https://blog.sourceclear.com/property-based-testing-for-java...