Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quickcheck for non-boolean tests

I am using QuickCheck to test my code for some numeric calculations. Basically I have an exact function and several approximations of it that are much more efficient.

I'm currently implementing the properties I want to test something like:

prop_blah input = (abs $ (exact input)-(approx input)) < threshold

But it would be really nice to know exactly how accurate each of the approximation algorithms is and compare them with each other. One easy way to do this would be to get reports of the mean and standard deviation of the left hand side of the inequality. Is this somehow possible?

like image 428
Mike Izbicki Avatar asked Aug 13 '12 21:08

Mike Izbicki


1 Answers

If you only need it to be printed out, you should check QuickCheck Callbacks which are performed after a single test. Their definition is located in Test.QuickCheck.Property

Otherwise you could use the Function collect :: (Show a, Testable prop) => a -> prop -> Property located in Test.QuickCheck.Property.

let a = (abs $ (exact input)-(approx input))
in collect a (a < threshold)

This way you geld at least a string representation of the approximation and also get to know how many of the single tests give the same approximation.

You could even get rid of the approximation quality and just list the factors by doing:

prop = collect (abs $ (exact input)-(approx input)) True
like image 189
MoFu Avatar answered Sep 28 '22 15:09

MoFu