extrapolate-0.1.0: tests/test-extrapolate.hs
-- Copyright (c) 2017 Rudy Matela.
-- Distributed under the 3-Clause BSD licence (see the file LICENSE).
import Test
import Data.List (sort)
main :: IO ()
main = mainTest tests 10000
tests :: Int -> [Bool]
tests n =
[ True
-- Transforming lists into Exprs
, expr ([]::[Int]) == constant "[]" ([]::[Int])
, expr ([0::Int]) == zero -:- ll
, expr ([0::Int,1]) == zero -:- one -:- ll
, holds n $ \xs -> expr xs == foldr (-:-) ll (map expr (xs :: [Int]))
, holds n $ \ps -> expr ps == foldr (-:-) llb (map expr (ps :: [Bool]))
-- Transforming Maybes into Exprs
, expr (Nothing :: Maybe Int) == nothing
, expr (Nothing :: Maybe Bool) == nothingBool
, expr (Just 1 :: Maybe Int) == just one
, expr (Just False :: Maybe Bool) == just false
, holds n $ \x -> expr (Just x) == just (expr (x :: Int))
, holds n $ \p -> expr (Just p) == just (expr (p :: Bool))
-- Transforming Tuples into Exprs
, expr ((0,False) :: (Int,Bool)) == zero `comma` false
, expr ((True,1) :: (Bool,Int)) == true `comma` one
-- Showing of Exprs
, holds n $ \x -> show (expr x) == show (x :: ()) ++ " :: ()"
, holds n $ \x -> show (expr x) == show (x :: Int) ++ " :: Int"
, holds n $ \p -> show (expr p) == show (p :: Bool) ++ " :: Bool"
, holds n $ \x -> show (expr x) == show (x :: Integer) ++ " :: Integer"
, holds 9 $ \xs -> show (expr xs) == show (xs :: [()]) ++ " :: [()]"
, holds n $ \xs -> show (expr xs) == show (xs :: [Int]) ++ " :: [Int]"
, holds n $ \ps -> show (expr ps) == show (ps :: [Bool]) ++ " :: [Bool]"
, holds n $ \xs -> show (expr xs) == show (xs :: [Integer]) ++ " :: [Integer]"
, holds n $ \mx -> show (expr mx) == show (mx :: Maybe ()) ++ " :: Maybe ()"
, holds n $ \mx -> show (expr mx) == show (mx :: Maybe Int) ++ " :: Maybe Int"
, holds n $ \mp -> show (expr mp) == show (mp :: Maybe Bool) ++ " :: Maybe Bool"
, holds n $ \mx -> show (expr mx) == show (mx :: Maybe Integer) ++ " :: Maybe Integer"
, holds n $ \xy -> show (expr xy) == show (xy :: ((),Int)) ++ " :: ((),Int)"
, holds n $ \xy -> show (expr xy) == show (xy :: (Bool,Integer)) ++ " :: (Bool,Integer)"
, holds n $ \xyz -> show (expr xyz) == show (xyz :: ((),Int,Bool)) ++ " :: ((),Int,Bool)"
-- TODO: implement further tuple instances (4,5,6) and uncomment below
--, holds n $ \xyzw -> show (expr xyzw)
-- == show (xyzw :: ((),Int,Integer,Bool)) ++ " :: ((),Int,Integer,Bool)"
--, holds n $ \xyzwv -> show (expr xyzwv)
-- == show (xyzwv :: ((),Int,Integer,Bool,())) ++ " :: ((),Int,Integer,Bool,())"
--, holds n $ \xyzwvu -> show (expr xyzwvu)
-- == show (xyzwvu :: ((),Int,Integer,Bool,(),Int)) ++ " :: ((),Int,Integer,Bool,(),Int)"
, holds n $ idExprEval -:> ()
, holds n $ idExprEval -:> int
, holds n $ idExprEval -:> integer
, holds n $ idExprEval -:> bool
, holds n $ idExprEval -:> char
, holds 9 $ idExprEval -:> [()]
, holds n $ idExprEval -:> [int]
, holds n $ idExprEval -:> [integer]
, holds n $ idExprEval -:> [bool]
, holds n $ idExprEval -:> [char]
, holds n $ idExprEval -:> (mayb ())
, holds n $ idExprEval -:> (mayb int)
, holds n $ idExprEval -:> (mayb integer)
, holds n $ idExprEval -:> (mayb bool)
, holds n $ idExprEval -:> (mayb char)
, holds n $ idExprEval -:> (int,bool)
, holds n $ idExprEval -:> ((),integer)
, holds n $ idExprEval -:> ((),bool,integer)
-- TODO: implement further tuple instances (4,5,6) and uncomment below
--, holds n $ idExprEval -:> (int,(),bool,integer)
--, holds n $ idExprEval -:> (int,(),bool,integer,char)
--, holds n $ idExprEval -:> (string,int,(),bool,integer,char)
-- TODO: implement further tuple instances (7,8,9,10,11,12) and uncomment below
--, holds n $ idExprEval -:> ((),(),(),(),(),(),())
--, holds n $ idExprEval -:> ((),(),(),(),(),(),(),())
--, holds n $ idExprEval -:> ((),(),(),(),(),(),(),(),())
--, holds n $ idExprEval -:> ((),(),(),(),(),(),(),(),(),())
--, holds n $ idExprEval -:> ((),(),(),(),(),(),(),(),(),(),())
--, holds n $ idExprEval -:> ((),(),(),(),(),(),(),(),(),(),(),())
-- Silly test, as it basically replicates the actual implementation:
, backgroundOf int =$ sort $= [ constant "==" $ (==) -:> int
, constant "/=" $ (/=) -:> int
, constant "<=" $ (<=) -:> int
, constant "<" $ (<) -:> int
]
-- background tests
, listBackgroundOK ()
, listBackgroundOK int
, listBackgroundOK integer
, listBackgroundOK bool
, listBackgroundOK char
, listBackgroundOK [()]
, listBackgroundOK [int]
, listBackgroundOK [integer]
, listBackgroundOK [bool]
, listBackgroundOK [char]
, listBackgroundOK (mayb ())
, listBackgroundOK (mayb int)
, listBackgroundOK (mayb integer)
, listBackgroundOK (mayb bool)
, listBackgroundOK (mayb char)
, maybeBackgroundOK ()
, maybeBackgroundOK int
, maybeBackgroundOK integer
, maybeBackgroundOK bool
, maybeBackgroundOK char
, maybeBackgroundOK [()]
, maybeBackgroundOK [int]
, maybeBackgroundOK [integer]
, maybeBackgroundOK [bool]
, maybeBackgroundOK [char]
, maybeBackgroundOK (mayb ())
, maybeBackgroundOK (mayb int)
, maybeBackgroundOK (mayb integer)
, maybeBackgroundOK (mayb bool)
, maybeBackgroundOK (mayb char)
]
idExprEval :: (Eq a, Generalizable a) => a -> Bool
idExprEval x = eval (error "idExprEval: could not eval") (expr x) == x
listBackgroundOK :: Generalizable a => a -> Bool
listBackgroundOK x = backgroundOf [x] =$ sort $= backgroundListOf x
where
backgroundListOf x = [ constant "length" $ length -:> [x]
, constant "filter" $ filter ->:> [x]
]
+++ backgroundOf x
maybeBackgroundOK :: Generalizable a => a -> Bool
maybeBackgroundOK x = backgroundOf (mayb x) =$ sort $= backgroundMaybeOf x
where
backgroundMaybeOf x = [constant "Just" $ Just -:> x] +++ backgroundOf x