I have a program that takes a list and halves each even number in a list
halfEvens :: [Int] -> [Int]
halfEvens xs = [if x `mod` 2 == 0 then x `div` 2 else x | x <- xs]
and I want to write a quickCheck property for this functions which verifies if the initial and the compiled lists are equal if and only if there's no even number in that list
prop_evens xs = ((halfEvens xs == xs) && (length (filter (even) xs) == 0))
My problem is that this property failed after 3 tests. I have no idea what I'm doing wrong. Is the property I wrote wrong?
Counterexample:
[0]
contains an even number and is unaffected byhalfEvens
.You need to restrict that property to lists of nonzero elements. Exploit
(==>)
accordingly.