File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
src/unstable-consensus-testlib/Test/Util
test/storage-test/Test/Ouroboros/Storage/ChainDB Expand file tree Collapse file tree 2 files changed +27
-0
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 @@ -1607,6 +1607,14 @@ genBlk chunkInfo Model{..} =
16071607 )
16081608 ]
16091609
1610+ genSecurityParam :: Gen SecurityParam
1611+ genSecurityParam =
1612+ SecurityParam
1613+ . unsafeNonZero
1614+ . fromIntegral
1615+ . (+ 2 ) -- shift to the right to avoid degenerate cases
1616+ <$> geometric 0.5 -- range in [0, +inf); mean = 1/p = 2
1617+
16101618{- ------------------------------------------------------------------------------
16111619 Top-level tests
16121620-------------------------------------------------------------------------------}
You can’t perform that action at this time.
0 commit comments