From f774a92dd642a4e708c86449f689c77376fc13fc Mon Sep 17 00:00:00 2001 From: hasufell Date: Thu, 18 Dec 2014 03:53:27 +0100 Subject: [PATCH] TESTS: add MyPrelude tests --- CG2.cabal | 1 + Test/MyPrelude.hs | 43 +++++++++++++++++++++++++++++++++++++++++++ TestMain.hs | 5 +++++ 3 files changed, 49 insertions(+) create mode 100644 Test/MyPrelude.hs 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