on 4eaeb10 help sign in
62 lines 2.0 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 ((\\))
20import Test.QuickCheck (Property, Gen, choose, counterexample)
21import Test.QuickCheck.Monadic (PropertyM, assert, monitor, monadicIO)
23equals
24 :: (Show a, Monad m)
25 => (a -> a -> Bool) -> a -> a -> PropertyM m ()
26equals eq stream list = do
27 when (not $ stream `eq` list) $
28 monitor
29 (counterexample $
30 "stream " <> show stream
31 <> "\nlist " <> show list
32 )
33 assert (stream `eq` list)
35listEquals
36 :: (Show a, Eq a, MonadIO m)
37 => ([a] -> [a] -> Bool) -> [a] -> [a] -> PropertyM m ()
38listEquals eq stream list = do
39 when (not $ stream `eq` list) $ liftIO $ putStrLn $
40 "stream " <> show stream
41 <> "\nlist " <> show list
42 <> "\nstream length " <> show (length stream)
43 <> "\nlist length " <> show (length list)
44 <> "\nstream \\\\ list " <> show (stream \\ list)
45 <> "\nlist \\\\ stream " <> show (list \\ stream)
46 when (not $ stream `eq` list) $
47 monitor
48 (counterexample $
49 "stream " <> show stream
50 <> "\nlist " <> show list
51 <> "\nstream length " <> show (length stream)
52 <> "\nlist length " <> show (length list)
53 <> "\nstream \\\\ list " <> show (stream \\ list)
54 <> "\nlist \\\\ stream " <> show (list \\ stream)
55 )
56 assert (stream `eq` list)
58checkListEqual :: (Show a, Eq a) => [a] -> [a] -> Property
59checkListEqual ls_1 ls_2 = monadicIO (listEquals (==) ls_1 ls_2)
61chooseInt :: (Int, Int) -> Gen Int
62chooseInt = choose