File tree Expand file tree Collapse file tree 2 files changed +19
-8
lines changed
src/unstable-consensus-testlib/Test/Util
test/storage-test/Test/Ouroboros/Storage/ChainDB Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ module Test.Util.QuickCheck
2323 , frequency'
2424 , oneof'
2525
26+ -- * Sampling from distributions
27+ , geometric
28+
2629 -- * Comparing maps
2730 , isSubmapOfBy
2831
@@ -308,3 +311,19 @@ frequency' xs0 = lift (choose (1, tot)) >>= (`pick` xs0)
308311oneof' :: (MonadTrans t , Monad (t Gen )) => [t Gen a ] -> t Gen a
309312oneof' [] = error " QuickCheck.oneof used with empty list"
310313oneof' gs = lift (chooseInt (0 , length gs - 1 )) >>= (gs !! )
314+
315+ {- ------------------------------------------------------------------------------
316+ Sampling from distributions
317+ -------------------------------------------------------------------------------}
318+
319+ -- NOTE: if more advanced sampling is required, consider using 'mwc-random':
320+ -- https://hackage.haskell.org/package/mwc-random
321+
322+ -- | Sample from a geometric distribution
323+ geometric :: Double -> Gen Int
324+ geometric p
325+ | p <= 0 || p > 1 = error " p must be in (0,1]"
326+ | otherwise = do
327+ u <- choose (0.0 , 1.0 )
328+ let k = floor (log u / log (1 - p))
329+ return k
Original file line number Diff line number Diff line change @@ -1739,14 +1739,6 @@ genSecurityParam =
17391739 . fromIntegral
17401740 . (+ 2 ) -- shift to the right to avoid degenerate cases
17411741 <$> geometric 0.5 -- range in [0, +inf); mean = 1/p = 2
1742- where
1743- geometric :: Double -> Gen Int
1744- geometric p
1745- | p <= 0 || p > 1 = error " p must be in (0,1]"
1746- | otherwise = do
1747- u <- choose (0.0 , 1.0 )
1748- let k = floor (log u / log (1 - p))
1749- return k
17501742
17511743{- ------------------------------------------------------------------------------
17521744 Top-level tests
You can’t perform that action at this time.
0 commit comments