Skip to content

Commit e340c05

Browse files
more shrinking + another interesting test
1 parent b93df87 commit e340c05

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

quickcheck-dynamic/src/Test/QuickCheck/StateModel.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,9 @@ instance StateModel state => Arbitrary (ParallelActions state) where
706706
arbitrary = genParActions
707707

708708
shrink (ParallelActions actions as bs) =
709-
filter checkParallelActions [ ParallelActions actions as bs | actions <- QC.shrink actions ]
709+
filter checkParallelActions $ [ ParallelActions actions as bs | actions <- QC.shrink actions ] ++
710+
[ ParallelActions actions (tail as) bs | not $ null as ] ++
711+
[ ParallelActions actions as (tail bs) | not $ null bs ]
710712

711713
checkParallelActions :: StateModel state => ParallelActions state -> Bool
712714
checkParallelActions pas = checkWellTypedness commonCtx threadA && checkWellTypedness commonCtx threadB

quickcheck-dynamic/test/Spec/DynamicLogic/Counters.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ instance RunModel Counter (ReaderT (IORef Int) IO) where
105105

106106

107107
instance RunModelPar Counter (ReaderT (IORef Int) IO) where
108+
performPar Inc _ = do
109+
ref <- ask
110+
lift $ atomicModifyIORef ref (\ c -> (c+1, ()))
111+
-- lift $ do
112+
-- n <- readIORef ref
113+
-- threadDelay 50000
114+
-- writeIORef ref (n + 1)
115+
performPar Reset _ = do
116+
ref <- ask
117+
lift $ atomicModifyIORef ref (\ c -> (0, c))
118+
108119
postconditionPar (Counter n, _) Reset _ res = pure $ n == res
109120
postconditionPar _ _ _ _ = pure True
110121

0 commit comments

Comments
 (0)