haskellmonadsquickcheckrepa

Monadic QuickCheck test not working for arbitrary Repa array


I am trying to write tests for arbitrary Repa Arrays in Haskell. For some reason, the following snippet:

import Test.QuickCheck
import Test.QuickCheck.Monadic
import Data.Array.Repa (Array, DIM2)

prop_id :: Array U DIM2 Double -> Property
prop_id array = monadicIO $ array `R.equalsP` array >>= assert

throws this exception:

*** Failed! (after 1 test): 
Exception:
Test.QuickCheck.resize: negative size
CallStack (from HasCallStack):
    error, called at ./Test/QuickCheck/Gen.hs:82:22 in QuickCheck-2.9.2-Jyj4gc4JxkEIgGFLAsGhs9:Test.QuickCheck.Gen
Exception thrown while printing test case:
Test.QuickCheck.resize: negative size
CallStack (from HasCallStack):
    error, called at ./Test/QuickCheck/Gen.hs:82:22 in QuickCheck-2.9.2-Jyj4gc4JxkEIgGFLAsGhs9:Test.QuickCheck.Gen

I'm not sure how to interpret this information. Thanks for your help.


Solution

  • This is a bug in repa's Arbitrary instance. arbitrary crashes at size 0. You can fix the generator used by your property in the mean time:

    quickCheck $ forAll (scale (+1) arbitrary) prop_id