Skip to content

Commit

Permalink
refactoring #2 | review indentation of 'where' clause
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed Mar 11, 2019
1 parent 1163aeb commit 66db21a
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions test/unit/Cardano/Wallet/BlockSyncerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@ spec = do
]
forM_ ((L.take 10 . L.cycle) tests) $ \pair ->
uncurry tickingFunctionTest pair
where
tickingFunctionTest
:: String
-> DeliveryMode
-> SpecWith (Arg (IO ()))
tickingFunctionTest testDescr deliveryMode = it testDescr $ do
chunkSizesToTest <- generateBlockChunkSizes
tickingFunctionTime <- generate $ choose (1,3)
let testTime = (L.length chunkSizesToTest + 1)*(fromIntegral tickingFunctionTime)*1000*1000
let tickTime = (fromMicroseconds tickingFunctionTime*1000*1000)
consecutiveBlocks <- liftIO $ mkConsecutiveTestBlocks (sum chunkSizesToTest)
consumerData <- newEmptyMVar
putMVar consumerData $ BlocksConsumed []
producerData <- newEmptyMVar
putMVar producerData $ BlocksToInject (chunkSizesToTest,consecutiveBlocks)
blockToIOaction <- writeToIORefAction consumerData consecutiveBlocks
let blockDelivery = pushNextBlocks producerData deliveryMode
threadId <- forkIO $ tickingFunction blockDelivery blockToIOaction tickTime (BlockHeadersConsumed [])
threadDelay testTime
(BlocksConsumed obtainedData) <- takeMVar consumerData
killThread threadId
obtainedData `shouldBe` ((map fst . reverse) consecutiveBlocks)
where
tickingFunctionTest
:: String
-> DeliveryMode
-> SpecWith (Arg (IO ()))
tickingFunctionTest testDescr deliveryMode = it testDescr $ do
chunkSizesToTest <- generateBlockChunkSizes
tickingFunctionTime <- generate $ choose (1,3)
let testTime = (L.length chunkSizesToTest + 1)*(fromIntegral tickingFunctionTime)*1000*1000
let tickTime = (fromMicroseconds tickingFunctionTime*1000*1000)
consecutiveBlocks <- liftIO $ mkConsecutiveTestBlocks (sum chunkSizesToTest)
consumerData <- newEmptyMVar
putMVar consumerData $ BlocksConsumed []
producerData <- newEmptyMVar
putMVar producerData $ BlocksToInject (chunkSizesToTest,consecutiveBlocks)
blockToIOaction <- writeToIORefAction consumerData consecutiveBlocks
let blockDelivery = pushNextBlocks producerData deliveryMode
threadId <- forkIO $ tickingFunction blockDelivery blockToIOaction tickTime (BlockHeadersConsumed [])
threadDelay testTime
(BlocksConsumed obtainedData) <- takeMVar consumerData
killThread threadId
obtainedData `shouldBe` ((map fst . reverse) consecutiveBlocks)

mkConsecutiveTestBlocks
:: Int
Expand All @@ -80,28 +80,28 @@ mkConsecutiveTestBlocks
-- ^ returns block paired with generated hashes starting from the oldest
mkConsecutiveTestBlocks blockNum =
loop blockNum []
where
loop
:: Int
-> [((Hash "BlockHeader"),Block)]
-> IO [((Hash "BlockHeader"),Block)]
loop blockNumToGo res = do
let bytelistGenerator = pack <$> vector 10 :: Gen ByteString
if blockNumToGo <= 0 then
return $ reverse res
else
case res of
[] -> do
lastBlockHeader <- Hash <$> generate bytelistGenerator
theBlockHeader <- Hash <$> generate bytelistGenerator
let theEpoch = 0
let theSlot = 1
let theBlock = Block (BlockHeader theEpoch theSlot lastBlockHeader) Set.empty
loop (blockNumToGo - 1) [(theBlockHeader, theBlock)]
(lastBlockHeader, Block (BlockHeader lastEpoch lastSlot _) _ ):_ -> do
let theBlock = Block (BlockHeader lastEpoch (lastSlot + 1) lastBlockHeader) Set.empty
theBlockHeader <- Hash <$> generate bytelistGenerator
loop (blockNumToGo - 1) $ (theBlockHeader, theBlock):res
where
loop
:: Int
-> [((Hash "BlockHeader"),Block)]
-> IO [((Hash "BlockHeader"),Block)]
loop blockNumToGo res = do
let bytelistGenerator = pack <$> vector 10 :: Gen ByteString
if blockNumToGo <= 0 then
return $ reverse res
else
case res of
[] -> do
lastBlockHeader <- Hash <$> generate bytelistGenerator
theBlockHeader <- Hash <$> generate bytelistGenerator
let theEpoch = 0
let theSlot = 1
let theBlock = Block (BlockHeader theEpoch theSlot lastBlockHeader) Set.empty
loop (blockNumToGo - 1) [(theBlockHeader, theBlock)]
(lastBlockHeader, Block (BlockHeader lastEpoch lastSlot _) _ ):_ -> do
let theBlock = Block (BlockHeader lastEpoch (lastSlot + 1) lastBlockHeader) Set.empty
theBlockHeader <- Hash <$> generate bytelistGenerator
loop (blockNumToGo - 1) $ (theBlockHeader, theBlock):res


newtype BlocksConsumed = BlocksConsumed [(Hash "BlockHeader")] deriving (Show, Eq)
Expand Down Expand Up @@ -149,10 +149,10 @@ generateBlockChunkSizes :: IO [Int]
generateBlockChunkSizes = do
numberOfTicks <- generate $ choose (1,15)
generate $ generateBlockChunks numberOfTicks
where
generateBlockChunks
:: Int
-> Gen [Int]
generateBlockChunks numberOfTicks = do
let chunkSizeGen = choose (0,15)
vectorOf numberOfTicks chunkSizeGen
where
generateBlockChunks
:: Int
-> Gen [Int]
generateBlockChunks numberOfTicks = do
let chunkSizeGen = choose (0,15)
vectorOf numberOfTicks chunkSizeGen

0 comments on commit 66db21a

Please sign in to comment.