Skip to content

Commit 0decaa1

Browse files
committed
Add tests for Applicative and Monad instances
Unfortunately, these tests are rather slow, so I hid them behind a SLOW_TESTS macro. I don't know nearly enough about cabal to know how to arrange for tests to be run conditionally, so hopefully someone else can set that up properly.
1 parent 54c3603 commit 0decaa1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/seq-properties.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import qualified Prelude
1717
import qualified Data.List
1818
import Test.QuickCheck hiding ((><))
1919
import Test.QuickCheck.Poly
20+
#ifdef SLOW_TESTS
21+
import Test.QuickCheck.Function
22+
#endif
2023
import Test.Framework
2124
import Test.Framework.Providers.QuickCheck2
2225

@@ -93,6 +96,11 @@ main = defaultMain
9396
, testProperty "zipWith3" prop_zipWith3
9497
, testProperty "zip4" prop_zip4
9598
, testProperty "zipWith4" prop_zipWith4
99+
#ifdef SLOW_TESTS
100+
, testProperty "<*>" prop_ap
101+
, testProperty "*>" prop_then
102+
, testProperty ">>=" prop_bind
103+
#endif
96104
]
97105

98106
------------------------------------------------------------------------
@@ -588,6 +596,26 @@ prop_zipWith4 xs ys zs ts =
588596
toList' (zipWith4 f xs ys zs ts) ~= Data.List.zipWith4 f (toList xs) (toList ys) (toList zs) (toList ts)
589597
where f = (,,,)
590598

599+
-- Applicative operations
600+
601+
#ifdef SLOW_TESTS
602+
prop_ap :: Seq A -> Seq B -> Bool
603+
prop_ap xs ys =
604+
toList' ((,) <$> xs <*> ys) ~= ( (,) <$> toList xs <*> toList ys )
605+
606+
prop_then :: Seq A -> Seq B -> Bool
607+
prop_then xs ys =
608+
toList' (xs *> ys) ~= (toList xs *> toList ys)
609+
#endif
610+
611+
-- Monad operations
612+
613+
#ifdef SLOW_TESTS
614+
prop_bind :: Seq A -> Fun A (Seq B) -> Bool
615+
prop_bind xs (Fun _ f) =
616+
toList' (xs >>= f) ~= (toList xs >>= toList . f)
617+
#endif
618+
591619
-- Simple test monad
592620

593621
data M a = Action Int a

0 commit comments

Comments
 (0)