jeffh / Fox

Property Based Testing Library for Objective-C and Swift. QuickCheck for Apple's Platforms.
http://fox-testing.rtfd.org
Other
624 stars 30 forks source link

Is it possible to generate functions? #31

Open gfontenot opened 9 years ago

gfontenot commented 9 years ago

I'm writing a test suite to exercise the Functor, Applicative, and Monadic laws (thoughtbot/runes#2). Right now, I'm only generating the values, but it would be great to be able to generate functions to replace the append and prepend functions that I currently have. Since these laws should hold up for any value and any function, it would be awesome to be able to generate those as well.

jeffh commented 9 years ago

Hey @gfontenot,

I haven't looked much into generating functions. But theoretically it should be possible (Haskell QC can generate basic functions). Although dynamically generating functions is much more difficult in (Objective-)C. Blocks and Swift's interchangeable function/closures may allow it.

That being said, I haven't really explored more into generative functions. If you do end up trying let me know!

reiddraper commented 9 years ago

The paper Shrinking and Showing Functions describes Haskell's approach. Unfortunately the best public link I could find is behind the ACM paywall.

gfontenot commented 9 years ago

@jeffh Any pointers on where to start looking into that?

jeffh commented 9 years ago

Thanks @reiddraper for that link. I'll be adding that to my papers reading list.

@gfontenot unfortunately, I don't think I have anything profound.

Haskell's function generation is the only public implementation I know of (docs, source). I'd probably try porting that by reading a Haskell source (my ability is rudimentary at best). Otherwise, Reid's recommendation would be a good read. Getting some basic generation of blocks would probably be where I'd attempt first.