leancheck 0.6.0 → 0.6.1
raw patch · 11 files changed
+123/−55 lines, 11 files
Files
- LICENSE +1/−1
- README.md +1/−1
- TODO.md +7/−1
- leancheck.cabal +3/−2
- src/Test/LeanCheck/Core.hs +1/−1
- src/Test/LeanCheck/Error.hs +6/−7
- src/Test/LeanCheck/Function/CoListable.hs +28/−19
- src/Test/LeanCheck/Function/Eq.hs +7/−0
- src/Test/LeanCheck/Function/ShowFunction.hs +29/−6
- src/Test/LeanCheck/Tiers.hs +24/−1
- src/Test/LeanCheck/Utils/Types.hs +16/−16
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2015-2016, Rudy Matela+Copyright (c) 2015-2017, Rudy Matela All rights reserved.
README.md view
@@ -134,7 +134,7 @@ For an introduction to property-based testing and a step-by-step guide to LeanCheck, see the [tutorial on property-based testing with LeanCheck]-(`doc/tutorial.md` in the source repository).+\(`doc/tutorial.md` in the source repository). [LeanCheck's Haddock documentation]: https://hackage.haskell.org/package/leancheck/docs/Test-LeanCheck.html [tutorial on property-based testing with LeanCheck]: https://github.com/rudymatela/leancheck/blob/master/doc/tutorial.md
TODO.md view
@@ -29,7 +29,13 @@ * on data-invariant.md, write missing section; -v0.6.1+v0.6.2+------++* add copyright notices on modules using Haddock markup+++v0.6.3 ------ * implement stub `Test.LeanCheck.Function.*` modules;
leancheck.cabal view
@@ -11,7 +11,7 @@ -- this cabal file too complicated. -- Rudy name: leancheck-version: 0.6.0+version: 0.6.1 synopsis: Cholesterol-free property-based testing description: LeanCheck is a simple enumerative property-based testing library.@@ -50,7 +50,7 @@ source-repository this type: git location: https://github.com/rudymatela/leancheck- tag: v0.6.0+ tag: v0.6.1 library exposed-modules: Test.LeanCheck@@ -67,6 +67,7 @@ , Test.LeanCheck.Function , Test.LeanCheck.Function.ListsOfPairs , Test.LeanCheck.Function.CoListable+ , Test.LeanCheck.Function.Eq , Test.LeanCheck.Function.Periodic , Test.LeanCheck.Function.Show , Test.LeanCheck.Function.ShowFunction
src/Test/LeanCheck/Core.hs view
@@ -33,7 +33,7 @@ , counterExamples , witness , witnesses- , Testable+ , Testable(..) , results
src/Test/LeanCheck/Error.hs view
@@ -15,6 +15,7 @@ , witnesses , results + , fromError , errorToNothing , errorToFalse , errorToTrue@@ -47,7 +48,7 @@ import Control.Monad (liftM) import System.IO.Unsafe (unsafePerformIO)-import Data.Maybe (listToMaybe)+import Data.Maybe (listToMaybe, fromMaybe) import Control.Exception ( Exception , SomeException , ArithException@@ -89,15 +90,13 @@ return Nothing errorToFalse :: Bool -> Bool-errorToFalse p = case errorToNothing p of- Just p' -> p- Nothing -> False+errorToFalse = fromError False errorToTrue :: Bool -> Bool-errorToTrue p = case errorToNothing p of- Just p' -> p- Nothing -> True+errorToTrue = fromError True +fromError :: a -> a -> a+fromError x = fromMaybe x . errorToNothing holds,fails,exists :: Testable a => Int -> a -> Bool holds n = errorToFalse . C.holds n
src/Test/LeanCheck/Function/CoListable.hs view
@@ -8,6 +8,7 @@ import Test.LeanCheck+import Test.LeanCheck.Tiers import Data.Maybe (fromMaybe) @@ -17,51 +18,59 @@ class CoListable a where- coListing :: [[b]] -> [[a -> b]]+ cotiers :: [[b]] -> [[a -> b]] instance CoListable () where- coListing rs = mapT (\r () -> r) rs+ cotiers rs = mapT (\r () -> r) rs instance CoListable Bool where- coListing rs = productWith (\r1 r2 b -> if b then r1 else r2) rs rs+ cotiers rs = productWith (\r1 r2 b -> if b then r1 else r2) rs rs instance CoListable a => CoListable (Maybe a) where- coListing rs = productWith (\z f m -> case m of Nothing -> z- Just x -> f x) rs (coListing rs)+ cotiers rs = productWith (\z f m -> case m of+ Nothing -> z+ Just x -> f x) rs (cotiers rs) instance (CoListable a, CoListable b) => CoListable (Either a b) where- coListing rs = productWith (\f g e -> case e of Left x -> f x- Right x -> g x) (coListing rs) (coListing rs)+ cotiers rs = productWith (\f g e -> case e of+ Left x -> f x+ Right x -> g x) (cotiers rs) (cotiers rs) instance (CoListable a) => CoListable [a] where- coListing rss = mapT const rss- \+:/ productWith (\y f xs -> case xs of [] -> y- (x:xs') -> f x xs') rss (coListing (coListing rss))+ cotiers rss = mapT const rss+ \+:/ productWith+ (\y f xs -> case xs of+ [] -> y+ (x:xs') -> f x xs')+ rss+ (cotiers (cotiers rss)) ++ instance CoListable Int where- coListing rss = mapT const rss- \+:/ product3With (\f g z i -> if i > 0 then f (i-1)- else if i < 0 then g (i+1)- else z) (coListing rss) (coListing rss) rss+ cotiers rss = mapT const rss+ \+:/ productWith+ (\f g i -> if i >= 0 then f (i-1) else g (i+1))+ (cotiers rss) (cotiers rss) alts0 :: [[a]] -> [[a]] alts0 = id alts1 :: CoListable a => [[b]] -> [[a->b]]-alts1 bs = coListing bs+alts1 bs = cotiers bs alts2 :: (CoListable a, CoListable b) => [[c]] -> [[a->b->c]]-alts2 cs = coListing (coListing cs)+alts2 cs = cotiers (cotiers cs) alts3 :: (CoListable a, CoListable b, CoListable c) => [[d]] -> [[a->b->c->d]]-alts3 ds = coListing (coListing (coListing ds))+alts3 ds = cotiers (cotiers (cotiers ds)) -fListing :: (CoListable a, Listable b) => [[a->b]]-fListing = coListing tiers+ftiers :: (CoListable a, Listable b) => [[a->b]]+ftiers = cotiers tiers
+ src/Test/LeanCheck/Function/Eq.hs view
@@ -0,0 +1,7 @@+-- A toy Eq instance for Functions.+module Test.LeanCheck.Function.Eq () where++import Test.LeanCheck.Core++instance (Listable a, Eq b) => Eq (a -> b) where+ f == g = and [f x == g x | x <- take 60 list]
src/Test/LeanCheck/Function/ShowFunction.hs view
@@ -27,6 +27,7 @@ import Test.LeanCheck.Core import Test.LeanCheck.Error (errorToNothing)+import Test.LeanCheck.Utils.Types import Data.List import Data.Maybe @@ -63,15 +64,19 @@ tBindingsShow :: Show a => a -> [[Binding]] tBindingsShow x = [[([],errorToNothing $ show x)]] -instance ShowFunction () where tBindings = tBindingsShow-instance ShowFunction Bool where tBindings = tBindingsShow-instance ShowFunction Int where tBindings = tBindingsShow-instance ShowFunction Char where tBindings = tBindingsShow+instance ShowFunction () where tBindings = tBindingsShow+instance ShowFunction Bool where tBindings = tBindingsShow+instance ShowFunction Int where tBindings = tBindingsShow+instance ShowFunction Integer where tBindings = tBindingsShow+instance ShowFunction Char where tBindings = tBindingsShow+instance ShowFunction Float where tBindings = tBindingsShow+instance ShowFunction Double where tBindings = tBindingsShow+instance ShowFunction Ordering where tBindings = tBindingsShow instance Show a => ShowFunction [a] where tBindings = tBindingsShow instance Show a => ShowFunction (Maybe a) where tBindings = tBindingsShow+instance (Show a, Show b) => ShowFunction (Either a b) where tBindings = tBindingsShow instance (Show a, Show b) => ShowFunction (a,b) where tBindings = tBindingsShow - -- instance for functional value type -- instance (Show a, Listable a, ShowFunction b) => ShowFunction (a->b) where tBindings f = concatMapT tBindingsFor tiers@@ -158,7 +163,7 @@ then "undefined" else casePat ++ sep ++ cases --- instances for further tuples --+-- instances for further tuple arities -- instance (Show a, Show b, Show c) => ShowFunction (a,b,c) where tBindings = tBindingsShow instance (Show a, Show b, Show c, Show d)@@ -171,3 +176,21 @@ => ShowFunction (a,b,c,d,e,f,g) where tBindings = tBindingsShow instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h) => ShowFunction (a,b,c,d,e,f,g,h) where tBindings = tBindingsShow++-- instance for types from Test.LeanCheck.Utils.Types+instance ShowFunction Nat where tBindings = tBindingsShow+instance ShowFunction Nat1 where tBindings = tBindingsShow+instance ShowFunction Nat2 where tBindings = tBindingsShow+instance ShowFunction Nat3 where tBindings = tBindingsShow+instance ShowFunction Nat4 where tBindings = tBindingsShow+instance ShowFunction Nat5 where tBindings = tBindingsShow+instance ShowFunction Nat6 where tBindings = tBindingsShow+instance ShowFunction Nat7 where tBindings = tBindingsShow+instance ShowFunction Int1 where tBindings = tBindingsShow+instance ShowFunction Int2 where tBindings = tBindingsShow+instance ShowFunction Int3 where tBindings = tBindingsShow+instance ShowFunction Int4 where tBindings = tBindingsShow+instance ShowFunction Word1 where tBindings = tBindingsShow+instance ShowFunction Word2 where tBindings = tBindingsShow+instance ShowFunction Word3 where tBindings = tBindingsShow+instance ShowFunction Word4 where tBindings = tBindingsShow
src/Test/LeanCheck/Tiers.hs view
@@ -14,6 +14,10 @@ , bagCons , noDupListCons + , maybeCons0+ , maybeCons1+ , maybeCons2+ -- * Products of tiers , product3 , product3With@@ -37,6 +41,8 @@ , deleteT , normalizeT+ , catMaybesT+ , mapMaybeT -- * Tiers of choices , choices@@ -87,8 +93,18 @@ -- | Given a constructor that takes a list with no duplicate elements, -- return tiers of applications of this constructor. noDupListCons :: Listable a => ([a] -> b) -> [[b]]-noDupListCons f = mapT f (noDupListsOf tiers)+noDupListCons = (`mapT` noDupListsOf tiers) +maybeCons0 :: Maybe b -> [[b]]+maybeCons0 Nothing = []+maybeCons0 (Just x) = [[x]]++maybeCons1 :: Listable a => (a -> Maybe b) -> [[b]]+maybeCons1 f = mapMaybeT f tiers `addWeight` 1++maybeCons2 :: (Listable a, Listable b) => (a -> b -> Maybe c) -> [[c]]+maybeCons2 f = mapMaybeT (uncurry f) tiers `addWeight` 1+ -- | Like '><', but over 3 lists of tiers. product3 :: [[a]] -> [[b]]-> [[c]] -> [[(a,b,c)]] product3 = product3With (\x y z -> (x,y,z))@@ -221,6 +237,13 @@ normalizeT [] = [] normalizeT [[]] = [] normalizeT (xs:xss) = xs:normalizeT xss++-- | Concatenate tiers of maybes+catMaybesT :: [[Maybe a]] -> [[a]]+catMaybesT = map catMaybes++mapMaybeT :: (a -> Maybe b) -> [[a]] -> [[b]]+mapMaybeT f = catMaybesT . mapT f -- | Takes as argument tiers of element values; -- returns tiers of lists with no repeated elements.
src/Test/LeanCheck/Utils/Types.hs view
@@ -18,22 +18,22 @@ -- > read "2" = -2 :: Int2 -- > abs minBound = minBound -- > negate n = 2^N - n :: WordN- Int1- , Int2- , Int3- , Int4- , Word1- , Word2- , Word3- , Word4- , Nat- , Nat1- , Nat2- , Nat3- , Nat4- , Nat5- , Nat6- , Nat7+ Int1 (..)+ , Int2 (..)+ , Int3 (..)+ , Int4 (..)+ , Word1 (..)+ , Word2 (..)+ , Word3 (..)+ , Word4 (..)+ , Nat (..)+ , Nat1 (..)+ , Nat2 (..)+ , Nat3 (..)+ , Nat4 (..)+ , Nat5 (..)+ , Nat6 (..)+ , Nat7 (..) -- * Aliases to word types (deprecated) , UInt1