Search code examples
haskellquickcheck

QuickCheck to Generate from Static Permutations List


Say that I have the data types:

data A = A1 | A2 | A3
data B = B1 A | B2 A

I can easily generate a list of all possibilities of B. I want to test all possible permutations, but I still want to use QuickCheck to spit out all the elements of the list where it is applied. In this case, I want to test that a rule is true for all possibilities, so I don't want to generate random data.

Assuming that I already have all possibilities in a list, how can I make QuickCheck output each element of the list exactly once? Giving the same exact set of values each time.


Solution

  • Presumably you have something like:

    prop_for_b :: B -> Bool
    prop_for_b = undefined
    
    test_for_b :: IO ()
    test_for_b = quickCheck prop_for_b
    

    You can use quickCheck and its variants on plain Bools and it will smartly only run one "test"; thus:

    prop_for_all_bs :: Bool
    prop_for_all_bs = all prop_for_b [{- ... -}]
    
    test_for_all_bs :: IO ()
    test_for_all_bs = quickCheck prop_for_all_bs