nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
713 stars 119 forks source link

Assuring exhaustiveness of Arbitrary instances #267

Closed sjakobi closed 4 years ago

sjakobi commented 5 years ago

I have a large sum type that often gets new constructors. I want to be sure that whenever I add a new constructor, I also update the Arbitrary instance to generate the new constructor.

There is a StackOverflow question offering some ad-hoc solutions for this problem. It's from 2014 though, so I'm wondering what the recommended solution is today.

Lysxia commented 5 years ago

Shameless plug: generic-random requires you to specify a weight for every constructor (disclaimer: I'm the author, and there are a few other packages in the same space on Hackage).

sjakobi commented 5 years ago

Props for the lovely docs, @Lysxia! :+1: I'll give generic-random a try.

Maybe QuickCheck should even recommend generic-random somewhere?

there are a few other packages in the same space on Hackage

Can you give me some pointers?

Lysxia commented 5 years ago

The alternatives I know of only implement uniform distributions (which makes them that much simpler to their benefit):

sjakobi commented 4 years ago

I'm very happy with generic-random so far! :)

Here is the Arbitrary instance that I needed it for.

I've also made an answer using generic-random to the SO question from above.

Thank you @Lysxia for the great support! :+1: