I have a simple function set of converse functions (simple shift codes):
encode, decode :: Int -> String -> String
and they test fine by some simple manual tests, but a quickCheck test reports a failure:
*** Failed! Falsifiable (after 8 tests and 4 shrinks):
"\254"
0
But running this same test by hand works fine:
*Main> decode 0 ( encode 0 "\254")
"c"
I'm not asking why it fails (that is something I'll chase down), but why does quickCheck fail when the (seemingly) same test by hand works?
I suspect it has to do with the character encoding, one decoding it and the other treating it as a String, but am not sure why.
This question is about how the testing works, not (yet!) the function or why it fails, but here is the code:
import Data.Char
let2int c = ord c - ord 'a'
int2let n = chr (ord 'a' + n)
shift :: Int -> Char -> Char
shift n c | isLower c = int2let ((let2int c + n) `mod` 26)
| otherwise = c
encode, decode :: Int -> String -> String
encode n xs = [shift n x | x <- xs]
decode n = encode (-n)
Ref: Hutton, 2007
quickCheck $ (\s n-> (decode n $ encode n s) == s)