[tests] add better range integer generation. by default the number generated are fairly small.
This commit is contained in:
parent
3eda859c8d
commit
f79081670c
@ -1,12 +1,16 @@
|
|||||||
module Utils where
|
module Utils where
|
||||||
|
|
||||||
|
import Control.Applicative
|
||||||
import Control.Monad (replicateM)
|
import Control.Monad (replicateM)
|
||||||
import Data.Char
|
import Data.Char
|
||||||
import Data.Word
|
import Data.Word
|
||||||
|
import Data.List
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
import qualified Data.ByteString as B
|
import qualified Data.ByteString as B
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
import Crypto.Random
|
import Crypto.Random
|
||||||
|
import Crypto.Number.Serialize (os2ip)
|
||||||
|
import Prelude
|
||||||
|
|
||||||
import Test.Tasty.QuickCheck
|
import Test.Tasty.QuickCheck
|
||||||
|
|
||||||
@ -43,6 +47,23 @@ newtype Int0_2901 = Int0_2901 Int
|
|||||||
instance Arbitrary Int0_2901 where
|
instance Arbitrary Int0_2901 where
|
||||||
arbitrary = Int0_2901 `fmap` choose (0,2901)
|
arbitrary = Int0_2901 `fmap` choose (0,2901)
|
||||||
|
|
||||||
|
-- | a integer wrapper with a better range property
|
||||||
|
newtype QAInteger = QAInteger { getQAInteger :: Integer }
|
||||||
|
deriving (Show,Eq)
|
||||||
|
|
||||||
|
instance Arbitrary QAInteger where
|
||||||
|
arbitrary = oneof
|
||||||
|
[ QAInteger . fromIntegral <$> (choose (0, 655536) :: Gen Int) -- small integer
|
||||||
|
, larger <$> choose (0,4096) <*> choose (0, 65536) -- medium integer
|
||||||
|
, QAInteger . os2ip . B.pack <$> (choose (0,32) >>= \n -> replicateM n arbitrary) -- [ 0 .. 2^32 ] sized integer
|
||||||
|
]
|
||||||
|
where
|
||||||
|
larger :: Int -> Int -> QAInteger
|
||||||
|
larger p b = QAInteger (fromIntegral p * somePrime + fromIntegral b)
|
||||||
|
|
||||||
|
somePrime :: Integer
|
||||||
|
somePrime = 18446744073709551557
|
||||||
|
|
||||||
arbitraryBS :: Int -> Gen ByteString
|
arbitraryBS :: Int -> Gen ByteString
|
||||||
arbitraryBS n = B.pack `fmap` replicateM n arbitrary
|
arbitraryBS n = B.pack `fmap` replicateM n arbitrary
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user