packages feed

speculate 0.3.2 → 0.3.3

raw patch · 6 files changed

+104/−13 lines, 6 files

Files

README.md view
@@ -97,16 +97,13 @@ Like QuickSpec, Speculate uses testing to speculate equational laws about given Haskell functions.  There are some differences: -|                   | Speculate                 | QuickSpec                         |-| ----------------: | ------------------------- | --------------------------------- |-| testing           | enumerative ([LeanCheck]) | random ([QuickCheck])             |-| equational laws   | yes (after completion)    | yes (as discovered)               |-| inequational laws | yes                       | no                                |-| conditional laws  | yes                       | restricted to a set of predicates |-| polymorphism      | no                        | yes                               |-| performance       | slower                    | faster                            |--For most examples, Speculate runs slower than QuickSpec 2 but faster than QuickSpec 1.+* Speculate tests enumeratively using [LeanCheck],+  QuickSpec tests randomly using [QuickCheck];+* Speculate is able to report inequalities directly;+* QuickSpec allows polymorphism, Speculate does not;+* For most examples,+  Speculate runs slower than QuickSpec 2+  but faster than QuickSpec 1.   More documentation@@ -116,6 +113,7 @@  Speculate has been subject to a paper, see the [Speculate Paper on Haskell Symposium 2017](https://matela.com.br/paper/speculate.pdf).+Speculate is also subject to a chapter in a [PhD Thesis (2017)].  [leancheck]: https://hackage.haskell.org/package/leancheck [LeanCheck]: https://hackage.haskell.org/package/leancheck@@ -125,6 +123,8 @@  [Cabal]:   https://www.haskell.org/cabal [Haskell]: https://www.haskell.org/++[PhD Thesis (2017)]: https://matela.com.br/paper/rudy-phd-thesis-2017.pdf  [`speculate`]: https://hackage.haskell.org/package/speculate/docs/Test-Speculate.html#v:speculate [`args`]:      https://hackage.haskell.org/package/speculate/docs/Test-Speculate.html#v:args
TODO.md view
@@ -9,6 +9,10 @@ current ------- +* improve out-of-the-box support for functions as data values (see `eg/fun.hs`)++* add fun0 example, where functions are not instances of Eq and Ord+ * consistency: rename semi to inqualities everywhere.  * improve printing by separating variables, constants and background constants.
speculate.cabal view
@@ -1,5 +1,5 @@ name:                speculate-version:             0.3.2+version:             0.3.3 synopsis:            discovery of properties about Haskell functions description:   Speculate automatically discovers laws about Haskell functions.@@ -18,7 +18,7 @@ maintainer:          Rudy Matela <rudy@matela.com.br> category:            Testing build-type:          Simple-cabal-version:       >=1.18+cabal-version:       1.18  extra-doc-files: README.md                , TODO.md@@ -31,12 +31,15 @@ source-repository this   type:            git   location:        https://github.com/rudymatela/speculate-  tag:             v0.3.2+  tag:             v0.3.3   library   exposed-modules: Test.Speculate                  , Test.Speculate.Args+                 , Test.Speculate.Function+                 , Test.Speculate.Function.A100+                 , Test.Speculate.Function.A1000                  , Test.Speculate.Report                  , Test.Speculate.Engine                  , Test.Speculate.Expr
+ src/Test/Speculate/Function.hs view
@@ -0,0 +1,44 @@+-- |+-- Module      : Test.Speculate.Function+-- Copyright   : (c) 2016-2018 Rudy Matela+-- License     : 3-Clause BSD  (see the file LICENSE)+-- Maintainer  : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- If should import this if you want Speculate to treat functions as data+-- values.  This exports a Listable instance for functions an a facility to+-- define Eq and Ord instances for functions.+--+-- Please see the @fun@ and @monad@ examples from Speculate's source+-- repository for more details.+module Test.Speculate.Function+  ( funToList+  , areEqualFor+  , compareFor+  )+where++import Test.Speculate+import Test.LeanCheck.Function+import Test.LeanCheck.Error (errorToNothing)+import Data.Function (on)++funToList :: Listable a => (a -> b) -> [Maybe b]+funToList f = map (errorToNothing . f) list++-- | This function can be used to define an Eq instance for functions based on+--   testing and equality of returned values, like so:+--+-- > instance (Listable a, Eq b) => Eq (a -> b) where+-- >   (==) = areEqualFor 100+areEqualFor :: (Listable a, Eq b) => Int -> (a -> b) -> (a -> b) -> Bool+areEqualFor n = (==) `on` (take n . funToList)++-- | This function can be used to define an Ord instance for functions based on+--   testing and ordering of returned values, like so:+--+-- > instance (Listable a, Ord b) => Ord (a -> b) where+-- >   compare = compareFor 100+compareFor :: (Listable a, Ord b) => Int -> (a -> b) -> (a -> b) -> Ordering+compareFor n = compare `on` (take n . funToList)
+ src/Test/Speculate/Function/A100.hs view
@@ -0,0 +1,20 @@+-- |+-- Module      : Test.Speculate.Function.A100+-- Copyright   : (c) 2018 Rudy Matela+-- License     : 3-Clause BSD  (see the file LICENSE)+-- Maintainer  : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- This module exports a Listable instance for functions along with two toy Eq+-- and Ord instances for functions based on 100 sample return values.+module Test.Speculate.Function.A100 () where++import Test.Speculate+import Test.Speculate.Function++instance (Listable a, Eq b) => Eq (a -> b) where+  (==) = areEqualFor 100++instance (Listable a, Ord b) => Ord (a -> b) where+  compare = compareFor 100
+ src/Test/Speculate/Function/A1000.hs view
@@ -0,0 +1,20 @@+-- |+-- Module      : Test.Speculate.Function.A1000+-- Copyright   : (c) 2018 Rudy Matela+-- License     : 3-Clause BSD  (see the file LICENSE)+-- Maintainer  : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- This module exports a Listable instance for functions along with two toy Eq+-- and Ord instances for functions based on 1000 sample return values.+module Test.Speculate.Function.A1000 () where++import Test.Speculate+import Test.Speculate.Function++instance (Listable a, Eq b) => Eq (a -> b) where+  (==) = areEqualFor 1000++instance (Listable a, Ord b) => Ord (a -> b) where+  compare = compareFor 1000