module Fake.Class where
import Control.Monad
import Fake.Combinators
import Fake.Types
class Fake a where
fake :: FGen a
instance Fake () where
fake :: FGen ()
fake = () -> FGen ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
instance Fake Bool where
fake :: FGen Bool
fake = (Bool, Bool) -> FGen Bool
forall a. Random a => (a, a) -> FGen a
fromRange (Bool
False,Bool
True)
instance Fake Ordering where
fake :: FGen Ordering
fake = [Ordering] -> FGen Ordering
forall a. [a] -> FGen a
elements [Ordering
LT, Ordering
EQ, Ordering
GT]
instance Fake a => Fake (Maybe a) where
fake :: FGen (Maybe a)
fake = [(Int, FGen (Maybe a))] -> FGen (Maybe a)
forall a. [(Int, FGen a)] -> FGen a
frequency [(Int
1, Maybe a -> FGen (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing), (Int
3, (a -> Maybe a) -> FGen a -> FGen (Maybe a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM a -> Maybe a
forall a. a -> Maybe a
Just FGen a
forall a. Fake a => FGen a
fake)]
instance (Fake a, Fake b) => Fake (Either a b) where
fake :: FGen (Either a b)
fake = [FGen (Either a b)] -> FGen (Either a b)
forall a. [FGen a] -> FGen a
oneof [(a -> Either a b) -> FGen a -> FGen (Either a b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM a -> Either a b
forall a b. a -> Either a b
Left FGen a
forall a. Fake a => FGen a
fake, (b -> Either a b) -> FGen b -> FGen (Either a b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM b -> Either a b
forall a b. b -> Either a b
Right FGen b
forall a. Fake a => FGen a
fake]
instance (Fake a, Fake b) => Fake (a,b) where
fake :: FGen (a, b)
fake = (a -> b -> (a, b)) -> FGen a -> FGen b -> FGen (a, b)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,) FGen a
forall a. Fake a => FGen a
fake FGen b
forall a. Fake a => FGen a
fake
instance (Fake a, Fake b, Fake c) => Fake (a,b,c) where
fake :: FGen (a, b, c)
fake = (a -> b -> c -> (a, b, c))
-> FGen a -> FGen b -> FGen c -> FGen (a, b, c)
forall (m :: * -> *) a1 a2 a3 r.
Monad m =>
(a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
liftM3 (,,) FGen a
forall a. Fake a => FGen a
fake FGen b
forall a. Fake a => FGen a
fake FGen c
forall a. Fake a => FGen a
fake
instance (Fake a, Fake b, Fake c, Fake d) => Fake (a,b,c,d) where
fake :: FGen (a, b, c, d)
fake = (a -> b -> c -> d -> (a, b, c, d))
-> FGen a -> FGen b -> FGen c -> FGen d -> FGen (a, b, c, d)
forall (m :: * -> *) a1 a2 a3 a4 r.
Monad m =>
(a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r
liftM4 (,,,) FGen a
forall a. Fake a => FGen a
fake FGen b
forall a. Fake a => FGen a
fake FGen c
forall a. Fake a => FGen a
fake FGen d
forall a. Fake a => FGen a
fake
instance (Fake a, Fake b, Fake c, Fake d, Fake e) => Fake (a,b,c,d,e) where
fake :: FGen (a, b, c, d, e)
fake = (a -> b -> c -> d -> e -> (a, b, c, d, e))
-> FGen a
-> FGen b
-> FGen c
-> FGen d
-> FGen e
-> FGen (a, b, c, d, e)
forall (m :: * -> *) a1 a2 a3 a4 a5 r.
Monad m =>
(a1 -> a2 -> a3 -> a4 -> a5 -> r)
-> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r
liftM5 (,,,,) FGen a
forall a. Fake a => FGen a
fake FGen b
forall a. Fake a => FGen a
fake FGen c
forall a. Fake a => FGen a
fake FGen d
forall a. Fake a => FGen a
fake FGen e
forall a. Fake a => FGen a
fake
instance (Fake a, Fake b, Fake c, Fake d, Fake e, Fake f)
=> Fake (a,b,c,d,e,f) where
fake :: FGen (a, b, c, d, e, f)
fake = (a -> b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> FGen (a -> b -> c -> d -> e -> f -> (a, b, c, d, e, f))
forall (m :: * -> *) a. Monad m => a -> m a
return (,,,,,)
FGen (a -> b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> FGen a -> FGen (b -> c -> d -> e -> f -> (a, b, c, d, e, f))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FGen a
forall a. Fake a => FGen a
fake FGen (b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> FGen b -> FGen (c -> d -> e -> f -> (a, b, c, d, e, f))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FGen b
forall a. Fake a => FGen a
fake FGen (c -> d -> e -> f -> (a, b, c, d, e, f))
-> FGen c -> FGen (d -> e -> f -> (a, b, c, d, e, f))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FGen c
forall a. Fake a => FGen a
fake FGen (d -> e -> f -> (a, b, c, d, e, f))
-> FGen d -> FGen (e -> f -> (a, b, c, d, e, f))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FGen d
forall a. Fake a => FGen a
fake FGen (e -> f -> (a, b, c, d, e, f))
-> FGen e -> FGen (f -> (a, b, c, d, e, f))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FGen e
forall a. Fake a => FGen a
fake FGen (f -> (a, b, c, d, e, f)) -> FGen f -> FGen (a, b, c, d, e, f)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FGen f
forall a. Fake a => FGen a
fake
instance (Fake a, Fake b, Fake c, Fake d, Fake e, Fake f, Fake g)
=> Fake (a,b,c,d,e,f,g) where
fake :: FGen (a, b, c, d, e, f, g)
fake = (a -> b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> FGen (a -> b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall (m :: * -> *) a. Monad m => a -> m a
return (,,,,,,)
FGen (a -> b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> FGen a
-> FGen (b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FGen a
forall a. Fake a => FGen a
fake FGen (b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> FGen b -> FGen (c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FGen b
forall a. Fake a => FGen a
fake FGen (c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> FGen c -> FGen (d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FGen c
forall a. Fake a => FGen a
fake FGen (d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> FGen d -> FGen (e -> f -> g -> (a, b, c, d, e, f, g))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FGen d
forall a. Fake a => FGen a
fake FGen (e -> f -> g -> (a, b, c, d, e, f, g))
-> FGen e -> FGen (f -> g -> (a, b, c, d, e, f, g))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FGen e
forall a. Fake a => FGen a
fake FGen (f -> g -> (a, b, c, d, e, f, g))
-> FGen f -> FGen (g -> (a, b, c, d, e, f, g))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FGen f
forall a. Fake a => FGen a
fake FGen (g -> (a, b, c, d, e, f, g))
-> FGen g -> FGen (a, b, c, d, e, f, g)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FGen g
forall a. Fake a => FGen a
fake