I am trying to write a prop that changes a Sudoku and then checks if it’s still valid.
However, I am not sure how to use the “oneof”-function properly. Can you give me some hints, please?
prop_candidates :: Sudoku -> Bool
prop_candidates su = isSudoku newSu && isOkay newSu
where
newSu = update su aBlank aCandidate
aCandidate = oneof [return x | x <- candidates su aBlank]
aBlank = oneof [return x | x <- (blanks su)]
Here are some more info…
type Pos = (Int, Int)
update :: Sudoku -> Pos -> Maybe Int -> Sudoku
blanks :: Sudoku -> [Pos]
candidates :: Sudoku -> Pos -> [Int]
[return x | x <- (blanks example)] :: (Monad m) => [m Pos]
I have struggeled with this prop for 3 hours now, so any ideas are welcome!
What I was driving at is that you have a type mix-up. Namely,
aBlankis not aPos, but aGen Pos, soupdate su aBlank aCandidatemakes no sense! In fact, what you want is a way to generate a new sudoku given an initial sudoku; in other words a functionNow we can write it:
or even simpler:
And the property looks like
Since there are instances
Sudoku -> Gen BoolisTestableas well (assuminginstance Arbitrary Sudoku).