Haskell QuickCheck best practices (especially when testing type classes)

后端 未结 3 1332
傲寒
傲寒 2020-12-15 18:22

I\'ve just started using QuickCheck with a bunch of Haskell code. I\'m behind the times, I know. This question is a two-parter:

Firstly, what are the general best-pr

3条回答
  •  Happy的楠姐
    2020-12-15 19:07

    It's tedious to write the same property for each instance

    You don't do this. You write the property once for the class:

    class Gen a where
        next :: a -> a
        prev :: a -> a
    
    np_prop :: (Eq a, Gen a) => a -> Bool
    np_prop a = prev (next a) == a
    

    Then to test it, you cast to a particular type:

    quickCheck (np_prop :: Int -> Bool)
    quickCheck (np_prop :: String -> Bool)
    

    Your other questions I can't help with.

提交回复
热议问题