[Haskell-beginners] creating a complement for a given given test
k.srikanth.opensource at gmail.com
Mon Aug 10 19:20:16 EDT 2009
I am trying to use the quickcheck to generate some test-data to test an
api, along the lines of
For the sake of example, I choose the following function to test
data Result = Valid | Invalid
api_under_test :: (Int,Int) -> Result
| (x == 1) = Valid
| otherwise = Invalid
I had the following valid-generator which worked quite easily(trivial)
validCombinations= [ (1,1), (1,2) ]
validGen = elements validCombinations
forAll validGen $ \xs ->
(api_under_test xs) == (Valid)
Now, I want to have a complement to state:
forall tuples not in validCombinations, the api_under_test must return
forAll invalidGen $ \xs ->
(api_under_test xs) == (Invalid)
However, inspite of all googling, and reading the various docs including
quickcheck, I am at loss on how I can elegantly define the "invalidGen"
generator. One possible way I can think is to have a customized generator,
that would generate two random numbers and then look up the tuple generated
against the validCombinations list.
However, I feel there just might be a better way of solving this.
Any suggestion on how I should be trying to solve this.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners