+{-# OPTIONS_GHC -fno-warn-orphans #-}
+
+module Test.Term where
+
+import Test.QuickCheck
+import Control.Applicative
+import Lambda.Parser.Fancy
+import Lambda.Term
+
+cP :: Term
+cP = tRead "(λa d c.(λa.e) b (λc.d)) ((λa.(λd.a) (λd c.b ((λa.a) a)) (a ((λa.(λd.e) ((λe.(λd b.a) (λa c.(λa a d.(λd.b (λa d.c) e) (λb b.c a (a d (λb d d e a.d (λb b.d))))) ((λb.a) c)) (d ((λc.(λd.a (λe.e)) (c d)) ((λe.b) a))) c (λa.d (e (λe.(λd c.b) a))) (c (b a)) a (λe.(λa b e b a.d) b)) ((λe.b) (λa.b)) ((λe d.b) b) e) b) ((λc c.a e) (λb.(λb.e) a)))) (λe.e) b (λd c e e c a.c)) a)"
+
+cY :: Term
+cY = tRead "λf.(λx.f (x x)) (λx.f (x x))"
+cI :: Term
+cI = tRead "λx.x"
+cK :: Term
+cK = tRead "λx y.x"
+cS :: Term
+cS = tRead "λx y z.x z (y z)"
+
+instance Arbitrary Term
+ where arbitrary = sized aTerm
+
+aVarName :: Gen String
+aVarName = oneof . map (pure . (:[])) $ ['a'..'e']
+
+aTypeName :: Gen String
+aTypeName = oneof . map (pure . (:[])) $ ['A'..'E']
+
+aComb :: Gen Term
+aComb = oneof . map pure $ [cS, cK, cI, cY]
+
+aVar :: Gen Term
+aVar = liftA Var aVarName
+
+aTerm :: Int -> Gen Term
+aTerm 0 = aVar
+aTerm n = oneof
+ [ aVar, aComb
+ , liftA2 Lam aVarName $ aTerm (n - 1)
+ , liftA2 App (aTerm (n `div` 2)) (aTerm (n `div` 2))
+ , liftA3 Let aVar (aTerm (n / 2)) (aTerm (n / 2))]
+
+--
+-- TODO: shrink Terms
+-- TODO: timed tests
+
+