diff --git a/CG2.cabal b/CG2.cabal index 24b2005..e308456 100644 --- a/CG2.cabal +++ b/CG2.cabal @@ -160,6 +160,7 @@ executable Test Parser.Meshparser Parser.PathParser QueueEx + Test.MyPrelude Test.Vector diff --git a/Test/MyPrelude.hs b/Test/MyPrelude.hs new file mode 100644 index 0000000..76ec682 --- /dev/null +++ b/Test/MyPrelude.hs @@ -0,0 +1,43 @@ +{-# OPTIONS_HADDOCK ignore-exports #-} +{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-} + +module Test.MyPrelude where + +import MyPrelude +import Test.QuickCheck + + +splitByProp1 :: Positive Int + -> NonEmptyList (Positive Int) + -> NonEmptyList (Positive Int) + -> Bool +splitByProp1 (Positive x) (NonEmpty xs) (NonEmpty ys) = + splitBy (== negate x) (xs' ++ [negate x] ++ ys') == [xs', ys'] + where + xs' = fmap getPositive xs + ys' = fmap getPositive ys + + +splitByProp2 :: Positive Int + -> NonEmptyList (Positive Int) + -> NonEmptyList (Positive Int) + -> Bool +splitByProp2 (Positive x) (NonEmpty xs) (NonEmpty ys) = + splitBy (== negate x) (xs' ++ [negate x] ++ ys' ++ [negate x] ++ xs') + == + [xs', ys', xs'] + where + xs' = fmap getPositive xs + ys' = fmap getPositive ys + + +-- splitting by an element that is not in the list should leave the list +-- untouched +splitByProp3 :: Positive Int + -> NonEmptyList (Positive Int) + -> Bool +splitByProp3 (Positive x) (NonEmpty xs) = + splitBy (== negate x) xs' == [xs'] + where + xs' = fmap getPositive xs + diff --git a/TestMain.hs b/TestMain.hs index 74f0658..0f8df40 100644 --- a/TestMain.hs +++ b/TestMain.hs @@ -2,6 +2,7 @@ import Test.QuickCheck +import Test.MyPrelude import Test.Vector @@ -51,3 +52,7 @@ main = do putStrLn "testing det:" deepCheck detProp1 deepCheck detProp2 + putStrLn "testing splitBy" + deepCheck splitByProp1 + deepCheck splitByProp2 + deepCheck splitByProp3