lambdacube3d / lambdacube-compiler

LambdaCube 3D is a Haskell-like purely functional language for GPU. Try it out:
http://lambdacube3d.com
Other
85 stars 9 forks source link

Newest version of QuickCheck breaks UnitTests.hs #8

Closed nick8325 closed 6 years ago

nick8325 commented 8 years ago

Just a heads-up that the following code in UnitTests.hs will not work correctly with the latest QuickCheck:

forAll' :: (TestShow a, Testable prop)
        => Gen a -> (a -> prop) -> Property
forAll' gen pf =
  MkProperty $
  gen >>= \x ->
    unProperty (counterexample (testShow x) (pf x))

It will only run 1 test instead of 100.

To fix this, forAll' has to wrap the property in again to indicate that it introduces nondeterminism (see the source code for QuickCheck's forAll for an example). Alternatively, a less fragile approach would be not to use forAll' but to define a modifier which handles TestShow and MonoidEq (untested):

newtype TS a = TS a deriving Arbitrary
instance TestShow a => Show (TS a) where show = testShow
instance MonoidEq a => Eq (TS a) where TS x == TS y = x =::= y

propMonoidAssociativity :: (Arbitrary m, MonoidEq m, TestShow m) => TS m -> TS m -> TS m -> Property
propMonoidAssociativity (TS x) (TS y) (TS z) =
  TS ((x <> y) <> z) === TS (x <> (y <> z))