Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Evaluation.Helpers
Contents
Description
Various helpers for defining evaluation tests.
Synopsis
- forAllByteString ∷ ∀ (m ∷ Type → Type). (Monad m, HasCallStack) ⇒ Int → Int → PropertyT m ByteString
- forAllByteStringThat ∷ ∀ (m ∷ Type → Type). (Monad m, HasCallStack) ⇒ (ByteString → Bool) → Int → Int → PropertyT m ByteString
- evaluateTheSame ∷ HasCallStack ⇒ Term TyName Name DefaultUni DefaultFun () → Term TyName Name DefaultUni DefaultFun () → PropertyT IO ()
- evaluatesToConstant ∷ ∀ (a ∷ Type). Contains DefaultUni a ⇒ a → Term TyName Name DefaultUni DefaultFun () → PropertyT IO ()
- assertEvaluatesToConstant ∷ ∀ (a ∷ Type). Contains DefaultUni a ⇒ a → Term TyName Name DefaultUni DefaultFun () → IO ()
- evaluateToHaskell ∷ ∀ (a ∷ Type). ReadKnownIn DefaultUni (Term Name DefaultUni DefaultFun ()) a ⇒ Term TyName Name DefaultUni DefaultFun () → PropertyT IO a
Generators
forAllByteString ∷ ∀ (m ∷ Type → Type). (Monad m, HasCallStack) ⇒ Int → Int → PropertyT m ByteString Source #
Given a lower and upper bound (both inclusive) on length, generate a ByteString
whose length
falls within these bounds. Furthermore, the generated ByteString
will show as a list of
hex-encoded bytes on a failure, instead of the default Show
output.
Note
It is the caller's responsibility to ensure that the bounds are sensible: that is, that neither the upper or lower bound are negative, and that the lower bound is not greater than the upper bound.
forAllByteStringThat ∷ ∀ (m ∷ Type → Type). (Monad m, HasCallStack) ⇒ (ByteString → Bool) → Int → Int → PropertyT m ByteString Source #
As forAllByteString
, but with a postcondition.
Note
If the postcondition is unlikely, the generator may eventually fail after too many retries. Ensure that the postcondition is likely to avoid problems.
Evaluation helpers
evaluateTheSame ∷ HasCallStack ⇒ Term TyName Name DefaultUni DefaultFun () → Term TyName Name DefaultUni DefaultFun () → PropertyT IO () Source #
Typechecks and evaluates both PLC expressions. If either of them fail to typecheck, fail the
test, noting what the failure was. If both typecheck, but either errors when run, fail the test,
noting the log(s) for any failing expression. If both run without error, compare the results
using ===
.
evaluatesToConstant ∷ ∀ (a ∷ Type). Contains DefaultUni a ⇒ a → Term TyName Name DefaultUni DefaultFun () → PropertyT IO () Source #
As evaluateTheSame
, but for cases where we want to compare a more complex computation to a
constant (as if by mkConstant
). This is slightly more efficient.
assertEvaluatesToConstant ∷ ∀ (a ∷ Type). Contains DefaultUni a ⇒ a → Term TyName Name DefaultUni DefaultFun () → IO () Source #
As evaluatesToConstant
, but for a unit instead of a property.
evaluateToHaskell ∷ ∀ (a ∷ Type). ReadKnownIn DefaultUni (Term Name DefaultUni DefaultFun ()) a ⇒ Term TyName Name DefaultUni DefaultFun () → PropertyT IO a Source #
Given a PLC expression and an intended type (via a type argument), typecheck the expression, evaluate it, then produce the required Haskell value from the results. If we fail at any stage, instead fail the test and report the failure.