cryptol-2.9.0: Cryptol: The Language of Cryptography

Cryptol.Testing.Random

Description

This module generates random values for Cryptol types.

Synopsis

Documentation

type Gen g x = Integer -> g -> (SEval x (GenValue x), g) Source #

Arguments

 :: RandomGen g => EvalOpts how to evaluate things -> Value Function under test -> [Gen g Concrete] Argument generators -> Integer Size -> g -> IO (TestResult, g)

Apply a testable value to some randomly-generated arguments. Returns Nothing if the function returned True, or Just counterexample if it returned False.

Please note that this function assumes that the generators match the supplied value, otherwise we'll panic.

Arguments

 :: RandomGen g => EvalOpts How to evaluate things -> Value Function to be used to calculate tests -> [Gen g Concrete] Argument generators -> Integer Size -> g Initial random state -> IO ([Value], Value, g) Arguments, result, and new random state

Arguments

 :: RandomGen g => g The random generator state -> EvalOpts How to evaluate things -> [Gen g Concrete] Generators for the function arguments -> Value The function itself -> Int How many tests? -> IO [([Value], Value)] A list of pairs of random arguments and computed outputs

Return a collection of random tests.

dumpableType :: forall g. RandomGen g => Type -> Maybe [Gen g Concrete] Source #

Given a (function) type, compute generators for the function's arguments. This is like testableTypeGenerators, but allows the result to be any finite type instead of just Bit.

Given a (function) type, compute generators for the function's arguments. Currently we do not support polymorphic functions. In principle, we could apply these to random types, and test the results.

randomValue :: (Backend sym, RandomGen g) => sym -> Type -> Maybe (Gen g sym) Source #

A generator for values of the given type. This fails if we are given a type that lacks a suitable random value generator.

randomBit :: (Backend sym, RandomGen g) => sym -> Gen g sym Source #

Generate a random bit value.

randomSize :: RandomGen g => Int -> Int -> g -> (Int, g) Source #

randomInteger :: (Backend sym, RandomGen g) => sym -> Gen g sym Source #

Generate a random integer value. The size parameter is assumed to vary between 1 and 100, and we use it to generate smaller numbers first.

randomIntMod :: (Backend sym, RandomGen g) => sym -> Integer -> Gen g sym Source #

randomRational :: (Backend sym, RandomGen g) => sym -> Gen g sym Source #

randomWord :: (Backend sym, RandomGen g) => sym -> Integer -> Gen g sym Source #

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 it to generate smaller numbers first.

randomStream :: (Backend sym, RandomGen g) => Gen g sym -> Gen g sym Source #

Generate a random infinite stream value.

randomSequence :: (Backend sym, RandomGen g) => Integer -> Gen g sym -> Gen g sym Source #

Generate a random sequence. This should be used for sequences other than bits. For sequences of bits use "randomWord".

randomTuple :: (Backend sym, RandomGen g) => [Gen g sym] -> Gen g sym Source #

Generate a random tuple value.

randomRecord :: (Backend sym, RandomGen g) => RecordMap Ident (Gen g sym) -> Gen g sym Source #

Generate a random record value.

Arguments

 :: (Backend sym, RandomGen g) => sym -> Integer Exponent width -> Integer Precision width -> Gen g sym

randomV :: Backend sym => sym -> TValue -> Integer -> SEval sym (GenValue sym) Source #

Produce a random value with the given seed. If we do not support making values of the given type, return zero of that type. TODO: do better than returning zero

A test result is either a pass, a failure due to evaluating to False, or a failure due to an exception raised during evaluation

Constructors

 Pass FailFalse [Value] FailError EvalError [Value]

evalTest :: EvalOpts -> Value -> [Value] -> IO TestResult Source #

Apply a testable value to some arguments. Note that this function assumes that the values come from a call to testableType (i.e., things are type-correct). We run in the IO monad in order to catch any EvalErrors.

testableType :: Type -> Maybe (Maybe Integer, [Type], [[Value]]) Source #

Given a (function) type, compute all possible inputs for it. We also return the types of the arguments and the total number of test (i.e., the length of the outer list.

Given a fully-evaluated type, try to compute the number of values in it. Returns Nothing for infinite types, user-defined types, polymorphic types, and, currently, function spaces. Of course, we can easily compute the sizes of function spaces, but we can't easily enumerate their inhabitants.

typeValues :: Type -> [Value] Source #

Returns all the values in a type. Returns an empty list of values, for types where typeSize returned Nothing.

data TestSpec m s Source #

Constructors

 TestSpec FieldstestFn :: Integer -> s -> m (TestResult, s) testProp :: StringThe property as entered by the usertestTotal :: Integer testPossible :: Maybe IntegerNothing indicates infinitytestRptProgress :: Integer -> Integer -> m () testClrProgress :: m () testRptFailure :: TestResult -> m () testRptSuccess :: m ()

Constructors

 TestReport FieldsreportResult :: TestResult reportProp :: StringThe property as entered by the userreportTestsRun :: Integer reportTestsPossible :: Maybe Integer

runTests :: Monad m => TestSpec m s -> s -> m TestReport Source #