[tests] make sure we don't use 0 for number parameters

This commit is contained in:
Vincent Hanquez 2015-08-27 15:00:31 +01:00
parent 676c8e6be1
commit 3af592e997
2 changed files with 13 additions and 8 deletions

View File

@ -20,22 +20,21 @@ serializationVectors =
]
tests = testGroup "number"
[ testProperty "num-bits" $ \(Int0_2901 i) ->
if i == 0 then True else
and [ (numBits (2^i-1) == i)
, (numBits (2^i) == i+1)
, (numBits (2^i + (2^i-1)) == i+1)
]
[ testProperty "num-bits" $ \(Int1_2901 i) ->
and [ (numBits (2^i-1) == i)
, (numBits (2^i) == i+1)
, (numBits (2^i + (2^i-1)) == i+1)
]
, testProperty "num-bits2" $ \(Positive i) ->
not (i `testBit` numBits i) && (i `testBit` (numBits i - 1))
, testProperty "generate-param" $ \testDRG (Int0_2901 bits) ->
, testProperty "generate-param" $ \testDRG (Int1_2901 bits) ->
let r = withTestDRG testDRG $ generateParams bits (Just SetHighest) False
in r >= 0 && numBits r == bits && testBit r (bits-1)
, testProperty "generate-param2" $ \testDRG (Int0_2901 m1bits) ->
let bits = m1bits + 1 -- make sure minimum is 2
r = withTestDRG testDRG $ generateParams bits (Just SetTwoHighest) False
in r >= 0 && numBits r == bits && testBit r (bits-1) && testBit r (bits-2)
, testProperty "generate-param-odd" $ \testDRG (Int0_2901 bits) ->
, testProperty "generate-param-odd" $ \testDRG (Int1_2901 bits) ->
let r = withTestDRG testDRG $ generateParams bits Nothing True
in r >= 0 && odd r
, testProperty "generate-range" $ \testDRG (Positive range) ->

View File

@ -46,9 +46,15 @@ instance Arbitrary ArbitraryBS0_2901 where
newtype Int0_2901 = Int0_2901 Int
deriving (Show,Eq,Ord)
newtype Int1_2901 = Int1_2901 Int
deriving (Show,Eq,Ord)
instance Arbitrary Int0_2901 where
arbitrary = Int0_2901 `fmap` choose (0,2901)
instance Arbitrary Int1_2901 where
arbitrary = Int1_2901 `fmap` choose (1,2901)
-- | a integer wrapper with a better range property
newtype QAInteger = QAInteger { getQAInteger :: Integer }
deriving (Show,Eq)