您如何创建一个属性,以检查提供的所有解决方案是否都是有效的解决方案,我需要将其作为属性输出,但是我不确定该如何做,我只知道如何为quickCheck属性执行Bool输出。请参阅下文,了解我的尝试以及如何运行的一般想法:
solve :: Sudoku -> Maybe Sudoku
solve s = solve' (blanks s) s
solve' :: [Pos] -> Sudoku -> Maybe Sudoku
solve' blankl s
| not (isOkay s) = Nothing
| isFilled s = Just s
| otherwise = listToMaybe [fromJust sol | n <- [1..9],
let sol = solve' (tail blankl) (update s (head blankl) (Just n)),
sol /= Nothing]
isSolutionOf :: Sudoku -> Sudoku -> Bool
isSolutionOf s1 s2 =
isOkay s1
&& isFilled s1
&& and [ a == b || b == Nothing |
(a,b) <- zip (concat (rows s1)) (concat (rows s2)) ]
prop_SolveSound :: Sudoku -> Property
prop_SolveSound s
| solution == Nothing = True
| otherwise = isSolutionOf (fromJust solution) s where
solution = solve s
[非常感谢您的帮助,我想我想问的是,如何将Bool
输出从prop_SolveSound
转换为Property
,这很清楚?
最简单的说,您可以使用property
方法进行转换,例如property
至Bool
。我建议查看Property
类的实例,并尝试了解它们各自的功能以及如何使用。