1

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.

GreenSaguaro
  • 2,968
  • 2
  • 22
  • 41
  • 2
    If you can easily generate all permutations yourself, why not do so in a unit test without invoking QuickCheck at all? QuickCheck doesn't do anything for you if you are generating your own cases. – Rein Henrichs Sep 06 '16 at 21:09
  • All of my tests are using QuickCheck. I think it is nicer having all of the data come from QuickCheck rather than doing something clunky for a special case. If QuickCheck can feed that list one by one to that check, then I think that is much cleaner. – GreenSaguaro Sep 06 '16 at 21:13

1 Answers1

1

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
Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380
  • Not at all along the lines of what I was thinking. Something totally different, but does exactly what I was looking for. And it a much simpler way. – GreenSaguaro Sep 07 '16 at 03:11