5

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:

  1. There is no unwrapping function like fromJust in Maybe, so it must accept Random Array and return Random Boolean, while I put the checking code in the Monadic expression.

  2. Therefore, the result of isShuffled will not be plain Boolean, but like m Boolean

  3. There is no suitable Testable in purescript-quickcheck for m 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)

  4. 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 like testableRandomArray to have Boolean or Result from a Random 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.

snowmantw
  • 1,611
  • 1
  • 13
  • 25

0 Answers0