on 041be85 help sign in
66 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 , chooseDouble
16 ) where
18import Control.Monad (when)
19import Control.Monad.IO.Class (MonadIO(..))
20import Data.List ((\\))
21import Test.QuickCheck (Property, Gen, choose, counterexample)
22import Test.QuickCheck.Monadic (PropertyM, assert, monitor, monadicIO)
24equals
25 :: (Show a, Monad m)
26 => (a -> a -> Bool) -> a -> a -> PropertyM m ()
27equals eq stream list = do
28 when (not $ stream `eq` list) $
29 monitor
30 (counterexample $
31 "stream " <> show stream
32 <> "\nlist " <> show list
33 )
34 assert (stream `eq` list)
36listEquals
37 :: (Show a, Eq a, MonadIO m)
38 => ([a] -> [a] -> Bool) -> [a] -> [a] -> PropertyM m ()
39listEquals eq stream list = do
40 when (not $ stream `eq` list) $ liftIO $ putStrLn $
41 "stream " <> show stream
42 <> "\nlist " <> show list
43 <> "\nstream length " <> show (length stream)
44 <> "\nlist length " <> show (length list)
45 <> "\nstream \\\\ list " <> show (stream \\ list)
46 <> "\nlist \\\\ stream " <> show (list \\ stream)
47 when (not $ stream `eq` list) $
48 monitor
49 (counterexample $
50 "stream " <> show stream
51 <> "\nlist " <> show list
52 <> "\nstream length " <> show (length stream)
53 <> "\nlist length " <> show (length list)
54 <> "\nstream \\\\ list " <> show (stream \\ list)
55 <> "\nlist \\\\ stream " <> show (list \\ stream)
56 )
57 assert (stream `eq` list)
59checkListEqual :: (Show a, Eq a) => [a] -> [a] -> Property
60checkListEqual ls_1 ls_2 = monadicIO (listEquals (==) ls_1 ls_2)
62chooseInt :: (Int, Int) -> Gen Int
63chooseInt = choose
65chooseDouble :: (Double, Double) -> Gen Double
66chooseDouble = choose