11module Suites.Set (tests ) where
22
3+ import Control.Concurrent.STM
34import qualified Control.Foldl as Foldl
5+ import Control.Monad (forM_ )
46import Control.Monad.Free
7+ import Data.Hashable
8+ import Data.List (nub , sort , splitAt )
9+ import Data.Word (Word8 )
510import qualified DeferredFolds.UnfoldlM as UnfoldlM
611import qualified Focus
7- import qualified StmContainers.Set as StmSet
812import qualified ListT
13+ import qualified StmContainers.Set as StmSet
14+ import System.IO.Unsafe (unsafePerformIO )
915import Test.QuickCheck.Instances ()
1016import Test.Tasty
1117import Test.Tasty.HUnit
1218import Test.Tasty.QuickCheck
13- import Prelude hiding (null , choose )
14- import System.IO.Unsafe (unsafePerformIO )
15- import Control.Monad (forM_ )
16- import Control.Concurrent.STM
17- import Data.Hashable
18- import Data.List (nub , sort , splitAt )
19- import Data.Word (Word8 )
19+ import Prelude hiding (choose , null )
2020
2121-- helpers
2222
@@ -47,20 +47,22 @@ instance Hashable TestKey where
4747
4848tests :: [TestTree ]
4949tests =
50- [ testProperty " sizeAndList" $
51- let gen = nub <$> listOf (choose (' a' , ' z' ))
52- prop xs =
53- length xs == stmSetSize
54- where
55- stmSetSize =
56- unsafePerformIO $ atomically $ do
57- s <- stmSetFromList xs
58- StmSet. size s
59- in forAll gen prop,
50+ [ testProperty " sizeAndList"
51+ $ let gen = nub <$> listOf (choose (' a' , ' z' ))
52+ prop xs =
53+ length xs == stmSetSize
54+ where
55+ stmSetSize =
56+ unsafePerformIO $ atomically $ do
57+ s <- stmSetFromList xs
58+ StmSet. size s
59+ in forAll gen prop,
6060 testProperty " fromListToListSetIsomorphism" $ \ (xs :: [Int ]) ->
6161 let setList =
62- unsafePerformIO $ atomically $
63- stmSetFromList xs >>= stmSetToList
62+ unsafePerformIO
63+ $ atomically
64+ $ stmSetFromList xs
65+ >>= stmSetToList
6466 in sort (nub xs) === sort setList,
6567 testProperty " listTNonAtomicIsomorphism" $ \ (xs :: [Int ]) ->
6668 let setList =
@@ -82,25 +84,28 @@ tests =
8284 return (sz, sort ls)
8385 expected =
8486 let remaining = nub (filter (`notElem` dropped) ks)
85- in (length remaining, sort remaining)
87+ in (length remaining, sort remaining)
8688 in (finalSize, finalList) === expected,
87- testCase " insert" $
88- assertEqual " " (sort [' a' ,' b' ,' c' ]) =<< do
89+ testCase " insert"
90+ $ assertEqual " " (sort [' a' , ' b' , ' c' ])
91+ =<< do
8992 atomically $ do
9093 s <- StmSet. new
9194 StmSet. insert ' a' s
9295 StmSet. insert ' c' s
9396 StmSet. insert ' b' s
9497 sort <$> stmSetToList s,
95- testCase " focusInsert" $
96- assertEqual " " (sort [' a' ,' b' ]) =<< do
98+ testCase " focusInsert"
99+ $ assertEqual " " (sort [' a' , ' b' ])
100+ =<< do
97101 atomically $ do
98102 s <- StmSet. new
99103 StmSet. focus (Focus. insert () ) ' a' s
100104 StmSet. focus (Focus. insert () ) ' b' s
101105 sort <$> stmSetToList s,
102- testCase " insertAndDelete" $
103- assertEqual " " [' b' ] =<< do
106+ testCase " insertAndDelete"
107+ $ assertEqual " " [' b' ]
108+ =<< do
104109 atomically $ do
105110 s <- StmSet. new
106111 StmSet. focus (Focus. insert () ) ' a' s
@@ -110,8 +115,9 @@ tests =
110115 testCase " nullAndNotNull" $ do
111116 assertEqual " " True =<< atomically (StmSet. null =<< StmSet. new)
112117 assertEqual " " False =<< atomically (StmSet. null =<< stmSetFromList [' a' ]),
113- testCase " nullAfterDeletingTheLastElement" $
114- assertEqual " " True =<< do
118+ testCase " nullAfterDeletingTheLastElement"
119+ $ assertEqual " " True
120+ =<< do
115121 atomically $ do
116122 s <- stmSetFromList [' a' ]
117123 StmSet. delete ' a' s
0 commit comments