[Haskell-beginners] using quickcheck for blackbox testing for
3rd party apps.
byorgey at seas.upenn.edu
Tue Oct 13 12:04:52 EDT 2009
On Mon, Oct 12, 2009 at 11:51:49AM +0530, Srikanth K wrote:
> However, being a newbie, I am not able to understand how I can extract the
> "Response" part from the IO Response.
> I want something as follows
> prop_App state_x command_y = (abstract_App state_x command_y ) == (real_App
> state_x command_y)
> The issue here is that since the reall_App would return a "IO Response" and
> not "Response" I cannot really compare the abstract_App with the real_App.
> Any thought on how I can extract the value from the "IO Response" so that I
> can compare the the two implementations for equvivalence.
The short answer is: you can't extract a Response from an IO Response.
Once something is infected with IO, there's no cure!* However, you can
compare the responses if you make the result of prop_App an IO action
prop_App :: State -> Command -> IO Bool
prop_App state_x command_y = do
realResponse <- real_App state_x command_y
return $ abstract_App state_x command_y == realResponse
Off the top of my head I'm not sure of the proper way to run such
monadic tests with QuickCheck, but it can definitely be done.
* Some smart-alecks might pipe up with something about unsafePerformIO
here. But that's not a cure, it's more like performing an emergency
tracheotomy with a ballpoint pen.
More information about the Beginners