QuickCheck支持美味道具

时间:2014-04-06 19:46:27

标签: haskell quickcheck

我试图从_prop示例转到在Tasty中写相同的东西。 (例如http://primitive-automaton.logdown.com/posts/142511/tdd-with-quickcheck

game9_prop :: Game9 -> Bool
game9_prop = (9==) . length . unGame . unGame9

这就是我尝试的美味:

qcTestGengame9 :: TestTree
qcTestGengame9 = QC.testProperty "Better gen rate" $ 
   \ (g :: Game9) -> length . unGame . unGame9 g == 9 --ERROR LINE

此转换为我提供了以下错误:

test/Tasty.hs:53:11:
Illegal type signature: `Game9'
Perhaps you intended to use -XScopedTypeVariables
In a pattern type-signature

这是Game9类型:

-- To make generation rate better
newtype Game9 = Game9 { unGame9 :: Game }
   deriving (Eq, Show)

instance Arbitrary Game9 where
   arbitrary = (Game9 . Game) `liftM` replicateM 9 arbitrary

1 个答案:

答案 0 :(得分:3)

要修复即时错误,请删除类型注释,即使用

qcTestGengame9 :: TestTree
qcTestGengame9 = QC.testProperty "Better gen rate" $ 
   \ g -> (length . unGame . unGame9) g == 9

表达式unGame9 g已确保g :: Game9

但实际上它更简单:定义game9_prop后,您可以使用

qcTestGengame9 :: TestTree
qcTestGengame9 = QC.testProperty "Better gen rate" game9_prop