on 4e04e47 help sign in
65 lines 2.1 kB history raw
1-- |
2-- Module : Streamly.Test.Common
3-- Copyright : (c) 2020 Composewell Technologies
4--
5-- License : BSD-3-Clause
6-- Maintainer : streamly@composewell.com
7-- Stability : experimental
8-- Portability : GHC
10module Streamly.Test.Common
11 ( equals
12 , listEquals
13 , checkListEqual
14 , chooseInt
15 ) where
17import Control.Monad (when)
18import Control.Monad.IO.Class (MonadIO(..))
19import Data.List ((\\))
20#if __GLASGOW_HASKELL__ < 808
21import Data.Semigroup ((<>))
22#endif
23import Test.QuickCheck (Property, Gen, choose, counterexample)
24import Test.QuickCheck.Monadic (PropertyM, assert, monitor, monadicIO)
26equals
27 :: (Show a, Monad m)
28 => (a -> a -> Bool) -> a -> a -> PropertyM m ()
29equals eq stream list = do
30 when (not $ stream `eq` list) $
31 monitor
32 (counterexample $
33 "stream " <> show stream
34 <> "\nlist " <> show list
35 )
36 assert (stream `eq` list)
38listEquals
39 :: (Show a, Eq a, MonadIO m)
40 => ([a] -> [a] -> Bool) -> [a] -> [a] -> PropertyM m ()
41listEquals eq stream list = do
42 when (not $ stream `eq` list) $ liftIO $ putStrLn $
43 "stream " <> show stream
44 <> "\nlist " <> show list
45 <> "\nstream length " <> show (length stream)
46 <> "\nlist length " <> show (length list)
47 <> "\nstream \\\\ list " <> show (stream \\ list)
48 <> "\nlist \\\\ stream " <> show (list \\ stream)
49 when (not $ stream `eq` list) $
50 monitor
51 (counterexample $
52 "stream " <> show stream
53 <> "\nlist " <> show list
54 <> "\nstream length " <> show (length stream)
55 <> "\nlist length " <> show (length list)
56 <> "\nstream \\\\ list " <> show (stream \\ list)
57 <> "\nlist \\\\ stream " <> show (list \\ stream)
58 )
59 assert (stream `eq` list)
61checkListEqual :: (Show a, Eq a) => [a] -> [a] -> Property
62checkListEqual ls_1 ls_2 = monadicIO (listEquals (==) ls_1 ls_2)
64chooseInt :: (Int, Int) -> Gen Int
65chooseInt = choose