【发布时间】:2016-03-01 23:47:15
【问题描述】:
我成功地对此进行了快速检查:
testaroo = quickCheck $ checkWin
checkWin :: [(Int, ThePlayers)] -> Bool
checkWin [(1,_),(2,_),(3,_)] = True
checkWin [(4,_),(5,_),(6,_)] = True
checkWin [(7,_),(8,_),(9,_)] = True
checkWin [(1,_),(5,_),(9,_)] = True
checkWin [(3,_),(5,_),(7,_)] = True
checkWin [(1,_),(4,_),(7,_)] = True
checkWin [(2,_),(5,_),(8,_)] = True
checkWin [(3,_),(6,_),(9,_)] = True
checkWin _ = False
但是当我尝试运行时
testaroo = quickCheck $ removeFromList
removeFromList :: (Int, ThePlayers) -> [(Int, ThePlayers)] -> [(Int, ThePlayers)]
removeFromList tuple list = delete tuple list
我遇到了以下情况:
No instance for (Arbitrary ThePlayers)
arising from a use of `quickCheck'
Possible fix:
add an instance declaration for (Arbitrary ThePlayers)
In the expression: quickCheck
In the expression: quickCheck $ removeFromList
In an equation for `testaroo':
testaroo = quickCheck $ removeFromList
Failed, modules loaded: none.
我在 checkWin 上成功运行我的 quickCheck 我做了什么我添加了
instance Arbitrary BoardState
where
arbitrary = arbitrary
但老实说,我不太确定这是做什么的 :)。无论如何我可以在我的removeFromList 函数上运行测试吗?
【问题讨论】:
-
您似乎没有在
checkWin中使用ThePlayers。为什么不只检查Int值的胜利?您可以使用map fst将[(Int, ThePlayers)]转换为[Int]。
标签: haskell quickcheck