1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
module Main.Sample where
import qualified Data.Vector as B
import Test.QuickCheck.Instances ()
import qualified Test.Tasty.QuickCheck as C
import qualified VectorBuilder.Builder as A
import Prelude
data Sample a
= Empty
| Singleton a
| Vector (Vector a)
| List [a]
deriving (Show)
toBuilder :: Sample a -> A.Builder a
toBuilder =
\case
Empty -> A.empty
Singleton a -> A.singleton a
Vector a -> A.vector a
List a -> A.foldable a
toVector :: Sample a -> Vector a
toVector =
\case
Empty -> B.empty
Singleton a -> B.singleton a
Vector a -> a
List a -> B.fromList a
instance (C.Arbitrary a) => C.Arbitrary (Sample a) where
arbitrary =
do
constructorIndex <- C.choose (0 :: Int, 3)
case constructorIndex of
0 -> return Empty
1 -> C.arbitrary >>= return . Singleton
2 -> C.arbitrary >>= return . Vector
3 -> C.arbitrary >>= return . List
_ -> error "Bug"
|