使用Test.Framework为代数数据类型实现QuickCheck Arbitrary

时间:2013-09-08 19:26:18

标签: haskell quickcheck

我正在尝试为ADT写一些quickcheck属性:

{-# LANGUAGE TemplateHaskell #-}

module Main where

import Test.QuickCheck
import Test.Framework.Providers.QuickCheck2
import Test.Framework.TH
import Test.Framework

-- Stub implementations, not relevant to this problem
encode x = x
decode x = x

data Activity = Run | Walk

instance Arbitrary Activity where
  arbitrary = elements [Run, Walk]

prop_activity_can_be_serialized :: Activity -> Bool
prop_activity_can_be_serialized x = (decode . encode) x == x

main :: IO ()
main = defaultMain [$testGroupGenerator]

这不编译:

Test.hs:23:25:
No instance for (QuickCheck-2.5.1.1:Test.QuickCheck.Arbitrary.Arbitrary
                   Activity)
  arising from a use of `testProperty'
Possible fix:
  add an instance declaration for
  (QuickCheck-2.5.1.1:Test.QuickCheck.Arbitrary.Arbitrary Activity)
In the expression: testProperty (Test.Framework.TH.fixName n)
In the expression:
  \ n -> testProperty (Test.Framework.TH.fixName n)
In the expression:
  \ n -> testProperty (Test.Framework.TH.fixName n)
    "prop_activity_can_be_serialized" prop_activity_can_be_serialized

...但我确实为Arbitrary Activity添加了一个实例声明。我错过了什么?

0 个答案:

没有答案