[Haskell-cafe] Ensuring Type Class instances follow the 'rules'
ryani.spam at gmail.com
Fri May 29 13:21:18 EDT 2009
Just pretend it was named "Test Driven Development" so it feels more
sexy while you read it :)
On Fri, May 29, 2009 at 5:05 AM, Hemanth Kapila <saihemanth at gmail.com> wrote:
> Thanks Eugene and wren.
> Serves me right, actually. The one chapter I skipped in RWH was the 11th one
> called "Testing and Quality Assurance" thinking it is too boring.
> On Fri, May 29, 2009 at 12:44 PM, wren ng thornton <wren at freegeek.org>
>> Eugene Kirpichov wrote:
>>> Use QuickCheck.
>> Also use SmallCheck or lazy SmallCheck.
>> All of these are automatic tools that allow you to specify laws and
>> automatically generate values for testing the law. QuickCheck generates
>> values randomly, which can be useful but is very often insufficient. Both
>> versions of SmallCheck do exhaustive search of all values down to a bounded
>> "depth" (lazy SmallCheck can often search deeper and faster).
>> If you want to have decent assurances of correctness then use (lazy)
>> SmallCheck. If you're dealing with a really branchy type which makes it
>> prohibitive to search to any reasonable depth, then use QuickCheck in
>> addition. Occasionally QuickCheck can be good for ferreting out really
>> obscure corner cases, but SmallCheck is much better about guaranteeing you
>> get all the basic cases.
>>  e.g.
>> prop_compare a b =
>> compare a b == negateOrdering (compare b a)
>> negateOrdering LT = GT
>> negateOrdering EQ = EQ
>> negateOrdering GT = LT
>> Live well,
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe