mirror of
https://github.com/GaloisInc/cryptol.git
synced 2024-12-17 04:44:39 +03:00
Fix exhaustive and random testing for integers-mod-n type.
This commit is contained in:
parent
7da2219caf
commit
30ba719343
@ -90,8 +90,8 @@ typeSize ty =
|
|||||||
(TCBit, _) -> Just 2
|
(TCBit, _) -> Just 2
|
||||||
(TCInteger, _) -> Nothing
|
(TCInteger, _) -> Nothing
|
||||||
(TCIntMod, [sz]) -> case tNoUser sz of
|
(TCIntMod, [sz]) -> case tNoUser sz of
|
||||||
TCon (TC (TCNum n)) _ -> Just n
|
TCon (TC (TCNum n)) _ | 0 < n -> Just n
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
(TCIntMod, _) -> Nothing
|
(TCIntMod, _) -> Nothing
|
||||||
(TCSeq, [sz,el]) -> case tNoUser sz of
|
(TCSeq, [sz,el]) -> case tNoUser sz of
|
||||||
TCon (TC (TCNum n)) _ -> (^ n) <$> typeSize el
|
TCon (TC (TCNum n)) _ -> (^ n) <$> typeSize el
|
||||||
|
@ -72,6 +72,12 @@ randomValue ty =
|
|||||||
|
|
||||||
(TC TCInteger, []) -> Just randomInteger
|
(TC TCInteger, []) -> Just randomInteger
|
||||||
|
|
||||||
|
(TC TCIntMod, [TCon (TC TCInf) []]) -> Just randomInteger
|
||||||
|
|
||||||
|
(TC TCIntMod, [TCon (TC (TCNum n)) []])
|
||||||
|
| 0 < n -> Just (randomIntMod n)
|
||||||
|
| otherwise -> Just randomInteger
|
||||||
|
|
||||||
(TC TCSeq, [TCon (TC TCInf) [], el]) ->
|
(TC TCSeq, [TCon (TC TCInf) [], el]) ->
|
||||||
do mk <- randomValue el
|
do mk <- randomValue el
|
||||||
return (randomStream mk)
|
return (randomStream mk)
|
||||||
@ -114,6 +120,11 @@ randomInteger _ g =
|
|||||||
(x, g2) = randomR (- 256^n, 256^n) g1
|
(x, g2) = randomR (- 256^n, 256^n) g1
|
||||||
in (VInteger (integerLit x), g2)
|
in (VInteger (integerLit x), g2)
|
||||||
|
|
||||||
|
randomIntMod :: (BitWord b w i, RandomGen g) => Integer -> Gen g b w i
|
||||||
|
randomIntMod modulus _ g =
|
||||||
|
let (x, g') = randomR (0, modulus-1) g
|
||||||
|
in (VInteger (integerLit x), g')
|
||||||
|
|
||||||
-- | Generate a random word of the given length (i.e., a value of type @[w]@)
|
-- | Generate a random word of the given length (i.e., a value of type @[w]@)
|
||||||
-- The size parameter is assumed to vary between 1 and 100, and we use
|
-- The size parameter is assumed to vary between 1 and 100, and we use
|
||||||
-- it to generate smaller numbers first.
|
-- it to generate smaller numbers first.
|
||||||
|
Loading…
Reference in New Issue
Block a user