Update tests for new generate(Safe)Prime

Update generatePrime test to test smaller bit sizes

Add test for generateSafePrime

Remove -fobject-code
This commit is contained in:
Colin Atkinson 2017-01-11 02:19:58 -05:00
parent 345f4cd141
commit a218b4ea3b
2 changed files with 9 additions and 7 deletions

View File

@ -205,7 +205,7 @@ Library
, bytestring
, memory >= 0.8
, ghc-prim
ghc-options: -Wall -fwarn-tabs -optc-O3 -fno-warn-unused-imports -fobject-code
ghc-options: -Wall -fwarn-tabs -optc-O3 -fno-warn-unused-imports
default-language: Haskell2010
cc-options: -std=gnu99
if flag(old_toolchain_inliner)

View File

@ -42,17 +42,19 @@ tests = testGroup "number"
in 0 <= r && r < range
, testProperty "generate-prime" $ \testDRG (Int0_2901 baseBits') ->
let baseBits = baseBits' `mod` 800
bits = 48 + baseBits -- no point generating lower than 48 bits ..
bits = 5 + baseBits -- generating lower than 5 bits causes an error ..
prime = withTestDRG testDRG $ generatePrime bits
-- with small base bits numbers, the probability that we "cross" this bit size ness
-- to the next is quite high, as the number generated has two highest bit set.
--
in bits == numBits prime || (if baseBits < 64 then (bits + 1) == numBits prime else False)
in bits == numBits prime
, testProperty "generate-safe-prime" $ \testDRG (Int0_2901 baseBits') ->
let baseBits = baseBits' `mod` 200
bits = 6 + baseBits
prime = withTestDRG testDRG $ generateSafePrime bits
in bits == numBits prime
, testProperty "marshalling" $ \qaInt ->
getQAInteger qaInt == os2ip (i2osp (getQAInteger qaInt) :: Bytes)
, testGroup "marshalling-kat-to-bytearray" $ map toSerializationKat $ zip [katZero..] serializationVectors
, testGroup "marshalling-kat-to-integer" $ map toSerializationKatInteger $ zip [katZero..] serializationVectors
]
]
where
toSerializationKat (i, (sz, n, ba)) = testCase (show i) (ba @=? i2ospOf_ sz n)
toSerializationKatInteger (i, (_, n, ba)) = testCase (show i) (n @=? os2ip ba)