module Test.Extrapolate.New
( generalizedCounterExamples
, lgg
, lgg1
)
where
import Test.Extrapolate.Core
generalizedCounterExamples :: Testable a => Int -> a -> [Exprs]
generalizedCounterExamples n p = gce $ counterExamples n p
where
passes = [as | (as,True) <- take n (results p)]
gce :: [Exprs] -> [Exprs]
gce [] = []
gce (e:es) = foldr1 incorporate (e:es)
: gce es
incorporate :: Exprs -> Exprs -> Exprs
g `incorporate` e = let g' = lgg g e
in if not $ any (`areInstancesOf` g') passes
then g'
else g
lgg1 :: Expr -> Expr -> Expr
lgg1 e1 e2 | typ e1 /= typ e2 =
error $ "lgg1: type mismatch: " ++ show e1 ++ ", " ++ show e2
lgg1 (e1f :$ e1x) (e2f :$ e2x) | typ e1f == typ e2f
&& typ e1x == typ e2x
= lgg1 e1f e2f :$ lgg1 e1x e2x
lgg1 e1@(Var _ _) _ = e1
lgg1 _ e2@(Var _ _) = e2
lgg1 e1 e2 | e1 == e2 = e1
| otherwise = holeOfTy $ typ e1
lgg :: Exprs -> Exprs -> Exprs
lgg = zipWith lgg1