Quickcheck for non-zero tests

I use QuickCheck to check my code for some numerical calculations. Basically, I have an exact function and a few of its approximations, which are much more efficient.

I am currently implementing properties that I want to check, for example:

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

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

+6
source share
1 answer

If you only need to print it, you should check the QuickCheck callbacks that run after one test. Their definition is in Test.QuickCheck.Property

Otherwise, you can 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) 

Thus, you get at least a string representation of the approximation, and also find out how many of the single tests give the same approximation.

You can even get rid of the quality of the approximation and simply list the factors by following these steps:

 prop = collect (abs $ (exact input)-(approx input)) True 
+2
source

Source: https://habr.com/ru/post/922776/


All Articles