I have a shuffle
function for Array
:
shuffle:: forall e. Array -> Eff (random :: RANDOM | e) Array
It shuffles an array in a Control.Monad.Eff.Random
monad and returns the wrapped one. I want to test the array is shuffled, like to compare the result is different, so I write QuickCheck code like:
quickCheck \arr -> isShuffled (shuffle arr)
However, I'm not sure how to write isShuffled
to match type definitions. Since:
There is no unwrapping function like
fromJust
inMaybe
, so it must acceptRandom Array
and returnRandom Boolean
, while I put the checking code in the Monadic expression.Therefore, the result of
isShuffled
will not be plainBoolean
, but likem Boolean
There is no suitable
Testable
inpurescript-quickcheck
form Boolean
, so I may need to create one instance for it, while the comment in QuickCheck refers:A testable property is a function of zero or more Arbitrary arguments, returning a Boolean or Result.
(code)However, again, I cannot extract/unwrap a value from
Random
monad, I don't know how to access the boolean inside it and to implement liketestableRandomArray
to haveBoolean
orResult
from aRandom Boolean
, unless I use some unsafe features.
I think I should "embed" the line of quickCheck
inside a Random monad so I can access the pure Array it shuffled. However, since it is quickCheck
to generate the test fixtures, I feel this is weird and no way to do that.