doctest icon indicating copy to clipboard operation
doctest copied to clipboard

Avoid QuickCheck for properties without free variables

Open bjornbm opened this issue 6 years ago • 2 comments

Properties that have no free variables and have type Bool can be checked to be True without using QuickCheck. Properties with free variables need QuickCheck. Some properties may not have free variables but if the type is not Bool we use QuickCheck on the assumption that they are of some other Test.QuickCheck.Testable instance.

The purpose of this pull request is to be able to benefit from the prop> syntax for simple properties without pulling in QuickCheck as a dependency.

An example in the wild:

--   >>> isRight (refine @(Not NonEmpty) @[Int] [])
--   True
--
--   >>> isLeft (refine @(Not NonEmpty) @[Int] [1,2])
--   True

Can be clearer (IMO) and more concisely written as:

prop> isRight (refine @(Not NonEmpty) @[Int] [])
prop> isLeft (refine @(Not NonEmpty) @[Int] [1,2])prop> 

(I will note that even when QuickCheck is not used prop> will be slower than >>> due to calling the repl twice.)

bjornbm avatar Jul 14 '19 22:07 bjornbm

Sorry, that failing test case got lost amongst noise related to cabal-v2 and GHC-8.6.5 on my local machine.

bjornbm avatar Jul 15 '19 09:07 bjornbm

Hmm. I can appreciate this as an optimisation, but the UX worries me a shade. At the moment, the rule is simple: if you use prop>, you need a QuickCheck dependency. With this patch, the rule gets more complicated. Is the win in test speed and not needing the QC dependencies sometimes worth the decrease in uniformity?

quasicomputational avatar Aug 04 '19 17:08 quasicomputational