A couple more tests and test cleanups

This commit is contained in:
Ryan Trinkle 2023-04-10 22:26:20 -04:00
parent e4f64347c9
commit 7a2d4162cf

View File

@ -19,8 +19,12 @@ testBoth = do
testUIOBadTimeless
putStrLn "testUIOMany"
testUIOMany
putStrLn "testUIOCycle"
testUIOCycle
putStrLn "testIO"
testIO
-- putStrLn "testUIOPrintLots"
-- testUIOPrintLots
{-# NOINLINE testUIOUnique #-}
testUIOUnique :: IO ()
@ -33,7 +37,8 @@ testUIOUnique = do
unordered $ atomicModifyIORef' r $ \v -> (v + 5, ())
unordered $ atomicModifyIORef' r2 $ \v -> (v + 10, ())
pure r
print =<< readIORef r
7 <- readIORef r
pure ()
{-# NOINLINE testUIOFix #-}
testUIOFix :: IO ()
@ -42,7 +47,8 @@ testUIOFix = do
unordered $ atomicModifyIORef' r $ \v -> (v + 5, ())
r <- timeless $ newIORef 2
pure r
print =<< readIORef r
7 <- readIORef r
pure ()
{-# NOINLINE testUIOBadTimeless #-}
testUIOBadTimeless :: IO ()
@ -51,7 +57,8 @@ testUIOBadTimeless = do
timeless $ atomicModifyIORef' r $ \v -> (v + 5, ())
r <- timeless $ newIORef 2
pure r
print =<< readIORef r
2 <- readIORef r
pure ()
{-# NOINLINE testUIOMany #-}
testUIOMany :: IO ()
@ -69,7 +76,8 @@ testUIOMany = do
unordered $ atomicModifyIORef' r $ \v -> (v + 9, ())
unordered $ atomicModifyIORef' r $ \v -> (v + 10, ())
pure r
print =<< readIORef r
55 <- readIORef r
pure ()
{-# NOINLINE testUIOReplicate #-}
testUIOReplicate :: IO ()
@ -79,12 +87,26 @@ testUIOReplicate = do
forM_ rs $ \r ->
unordered $ atomicModifyIORef' r $ \v -> (v + 5, ())
pure rs
vs <- mapM readIORef rs
print $ sum vs
70 <- fmap sum $ mapM readIORef rs
pure ()
{-# NOINLINE testUIOPrintLots #-}
testUIOPrintLots :: IO ()
testUIOPrintLots = runUIO2 $ do
replicateM_ 1000000 $ unordered $ putStrLn "Task"
newtype CycleRef = CycleRef (IORef CycleRef)
{-# NOINLINE testUIOCycle #-}
testUIOCycle :: IO ()
testUIOCycle = runUIO2 $ mdo
r <- timeless $ newIORef $ CycleRef r
pure ()
{-# NOINLINE testBoth #-}
testIO :: IO ()
testIO = do
r <- newIORef 2
atomicModifyIORef' r $ \v -> (v + 5, ())
print =<< readIORef r
7 <- readIORef r
pure ()