| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Skeletest.Predicate
Synopsis
- data Predicate (m :: Type -> Type) a
- anything :: forall (m :: Type -> Type) a. Monad m => Predicate m a
- eq :: forall a (m :: Type -> Type). (Eq a, Monad m) => a -> Predicate m a
- gt :: forall a (m :: Type -> Type). (Ord a, Monad m) => a -> Predicate m a
- gte :: forall a (m :: Type -> Type). (Ord a, Monad m) => a -> Predicate m a
- lt :: forall a (m :: Type -> Type). (Ord a, Monad m) => a -> Predicate m a
- lte :: forall a (m :: Type -> Type). (Ord a, Monad m) => a -> Predicate m a
- just :: forall (m :: Type -> Type) a. Monad m => Predicate m a -> Predicate m (Maybe a)
- nothing :: forall (m :: Type -> Type) a. Monad m => Predicate m (Maybe a)
- left :: forall (m :: Type -> Type) a b. Monad m => Predicate m a -> Predicate m (Either a b)
- right :: forall (m :: Type -> Type) b a. Monad m => Predicate m b -> Predicate m (Either a b)
- tup :: forall a (m :: Type -> Type). (IsPredTuple m a, Monad m) => ToPredTuple m a -> Predicate m a
- con :: forall a (m :: Type -> Type). a -> Predicate m a
- approx :: forall a (m :: Type -> Type). (Fractional a, Ord a, Monad m) => Tolerance -> a -> Predicate m a
- tol :: Tolerance
- data Tolerance = Tolerance {}
- (<<<) :: forall (m :: Type -> Type) a b. Monad m => Predicate m a -> (b -> a) -> Predicate m b
- (>>>) :: forall (m :: Type -> Type) b a. Monad m => (b -> a) -> Predicate m a -> Predicate m b
- not :: forall (m :: Type -> Type) a. Monad m => Predicate m a -> Predicate m a
- (&&) :: forall (m :: Type -> Type) a. Monad m => Predicate m a -> Predicate m a -> Predicate m a
- (||) :: forall (m :: Type -> Type) a. Monad m => Predicate m a -> Predicate m a -> Predicate m a
- and :: forall (m :: Type -> Type) a. Monad m => [Predicate m a] -> Predicate m a
- or :: forall (m :: Type -> Type) a. Monad m => [Predicate m a] -> Predicate m a
- any :: forall t (m :: Type -> Type) a. (Foldable t, Monad m) => Predicate m a -> Predicate m (t a)
- all :: forall t (m :: Type -> Type) a. (Foldable t, Monad m) => Predicate m a -> Predicate m (t a)
- elem :: forall a t (m :: Type -> Type). (Eq a, Foldable t, Monad m) => a -> Predicate m (t a)
- class HasSubsequences a where
- isPrefixOf :: a -> a -> Bool
- isInfixOf :: a -> a -> Bool
- isSuffixOf :: a -> a -> Bool
- hasPrefix :: forall a (m :: Type -> Type). (HasSubsequences a, Monad m) => a -> Predicate m a
- hasInfix :: forall a (m :: Type -> Type). (HasSubsequences a, Monad m) => a -> Predicate m a
- hasSuffix :: forall a (m :: Type -> Type). (HasSubsequences a, Monad m) => a -> Predicate m a
- returns :: MonadIO m => Predicate m a -> Predicate m (m a)
- throws :: (Exception e, MonadUnliftIO m) => Predicate m e -> Predicate m (m a)
- (===) :: (a -> b) -> (a -> b) -> IsoChecker a b
- isoWith :: (HasCallStack, Show a, Eq b) => Gen a -> Predicate PropertyM (IsoChecker a b)
- matchesSnapshot :: forall a (m :: Type -> Type). (Typeable a, MonadIO m) => Predicate m a
Documentation
General
Ord
Data types
left :: forall (m :: Type -> Type) a b. Monad m => Predicate m a -> Predicate m (Either a b) Source #
right :: forall (m :: Type -> Type) b a. Monad m => Predicate m b -> Predicate m (Either a b) Source #
tup :: forall a (m :: Type -> Type). (IsPredTuple m a, Monad m) => ToPredTuple m a -> Predicate m a Source #
Matches a tuple satisfying the given predicates. Works for tuples up to 6 elements.
P.tup (P.eq 1, P.gt 2, P.hasPrefix "hello ")
con :: forall a (m :: Type -> Type). a -> Predicate m a Source #
A predicate for checking that a value matches the given constructor.
It takes one argument, which is the constructor, except with all fields taking a Predicate instead of the normal value. Skeletest will rewrite the expression so it typechecks correctly.
>>>user `shouldSatisfy` P.con User{name = P.eq "user1", email = P.contains "@"}
Record fields that are omitted are not checked at all; i.e.
P.con Foo{} and P.con Foo{a = P.anything} are equivalent.
Numeric
approx :: forall a (m :: Type -> Type). (Fractional a, Ord a, Monad m) => Tolerance -> a -> Predicate m a Source #
A predicate for checking that a value is equal within some tolerance.
Useful for checking equality with floats, which might not be exactly equal. For more information, see: https://jvns.ca/blog/2023/01/13/examples-of-floating-point-problems/.
>>>(0.1 + 0.2) `shouldSatisfy` P.approx P.tol 0.3>>>(0.1 + 0.2) `shouldSatisfy` P.approx P.tol{P.rel = Just 1e-6} 0.3>>>(0.1 + 0.2) `shouldSatisfy` P.approx P.tol{P.abs = 1e-12} 0.3>>>(0.1 + 0.2) `shouldSatisfy` P.approx P.tol{P.rel = Just 1e-6, P.abs = 1e-12} 0.3>>>(0.1 + 0.2) `shouldSatisfy` P.approx P.tol{P.rel = Nothing} 0.3>>>(0.1 + 0.2) `shouldSatisfy` P.approx P.tol{P.rel = Nothing, P.abs = 1e-12} 0.3
Combinators
(<<<) :: forall (m :: Type -> Type) a b. Monad m => Predicate m a -> (b -> a) -> Predicate m b infixr 1 Source #
(>>>) :: forall (m :: Type -> Type) b a. Monad m => (b -> a) -> Predicate m a -> Predicate m b infixr 1 Source #
(&&) :: forall (m :: Type -> Type) a. Monad m => Predicate m a -> Predicate m a -> Predicate m a Source #
(||) :: forall (m :: Type -> Type) a. Monad m => Predicate m a -> Predicate m a -> Predicate m a Source #
Containers
any :: forall t (m :: Type -> Type) a. (Foldable t, Monad m) => Predicate m a -> Predicate m (t a) Source #
all :: forall t (m :: Type -> Type) a. (Foldable t, Monad m) => Predicate m a -> Predicate m (t a) Source #
elem :: forall a t (m :: Type -> Type). (Eq a, Foldable t, Monad m) => a -> Predicate m (t a) Source #
Subsequences
class HasSubsequences a where Source #
Methods
isPrefixOf :: a -> a -> Bool Source #
isInfixOf :: a -> a -> Bool Source #
isSuffixOf :: a -> a -> Bool Source #
Instances
| HasSubsequences Text Source # | |
| Eq a => HasSubsequences [a] Source # | |
Defined in Skeletest.Internal.Predicate | |
hasPrefix :: forall a (m :: Type -> Type). (HasSubsequences a, Monad m) => a -> Predicate m a Source #
hasInfix :: forall a (m :: Type -> Type). (HasSubsequences a, Monad m) => a -> Predicate m a Source #
hasSuffix :: forall a (m :: Type -> Type). (HasSubsequences a, Monad m) => a -> Predicate m a Source #
IO
Functions
(===) :: (a -> b) -> (a -> b) -> IsoChecker a b infix 2 Source #
Verify if two functions are isomorphic.
prop "reverse . reverse === id" $ do let genList = Gen.list (Gen.linear 0 10) $ Gen.int (Gen.linear 0 1000) (reverse . reverse) === id `shouldSatisfy` P.isoWith genList
isoWith :: (HasCallStack, Show a, Eq b) => Gen a -> Predicate PropertyM (IsoChecker a b) Source #
See (===).