speculate 0.2.3 → 0.2.4
raw patch · 35 files changed
+356/−39 lines, 35 files
Files
- README.md +8/−0
- speculate.cabal +2/−2
- src/Test/Speculate.hs +7/−1
- src/Test/Speculate/Args.hs +13/−2
- src/Test/Speculate/CondReason.hs +12/−2
- src/Test/Speculate/Engine.hs +9/−0
- src/Test/Speculate/Expr.hs +9/−0
- src/Test/Speculate/Expr/Canon.hs +9/−0
- src/Test/Speculate/Expr/Core.hs +9/−3
- src/Test/Speculate/Expr/Equate.hs +15/−7
- src/Test/Speculate/Expr/Ground.hs +9/−0
- src/Test/Speculate/Expr/Match.hs +9/−0
- src/Test/Speculate/Expr/TypeInfo.hs +12/−0
- src/Test/Speculate/Misc.hs +10/−2
- src/Test/Speculate/Pretty.hs +9/−1
- src/Test/Speculate/Reason.hs +12/−12
- src/Test/Speculate/Reason/Order.hs +9/−0
- src/Test/Speculate/Report.hs +9/−0
- src/Test/Speculate/Sanity.hs +9/−0
- src/Test/Speculate/SemiReason.hs +10/−1
- src/Test/Speculate/Utils.hs +9/−0
- src/Test/Speculate/Utils/Class.hs +9/−0
- src/Test/Speculate/Utils/Colour.hs +9/−1
- src/Test/Speculate/Utils/Digraph.hs +5/−0
- src/Test/Speculate/Utils/List.hs +16/−4
- src/Test/Speculate/Utils/Memoize.hs +9/−0
- src/Test/Speculate/Utils/Misc.hs +9/−0
- src/Test/Speculate/Utils/Ord.hs +9/−0
- src/Test/Speculate/Utils/PrettyPrint.hs +9/−1
- src/Test/Speculate/Utils/String.hs +9/−0
- src/Test/Speculate/Utils/Tiers.hs +9/−0
- src/Test/Speculate/Utils/Timeout.hs +9/−0
- src/Test/Speculate/Utils/Tuple.hs +5/−0
- src/Test/Speculate/Utils/Typeable.hs +27/−0
- tests/test-expr.hs +22/−0
README.md view
@@ -1,6 +1,9 @@ Speculate ========= +[![Speculate Build Status][build-status]][build-log]+[![Speculate on Hackage][hackage-version]][speculate-on-hackage]+ Speculate automatically discovers laws about Haskell functions. Give Speculate a bunch of Haskell functions and it will discover laws like: @@ -146,3 +149,8 @@ [QuickSpec]: https://github.com/nick8325/quickspec [QuickCheck]: https://hackage.haskell.org/package/QuickCheck [cmdargs]: https://hackage.haskell.org/package/cmdargs++[build-status]: https://travis-ci.org/rudymatela/speculate.svg?branch=master+[build-log]: https://travis-ci.org/rudymatela/speculate+[hackage-version]: https://img.shields.io/hackage/v/speculate.svg+[speculate-on-hackage]: https://hackage.haskell.org/package/speculate
speculate.cabal view
@@ -1,5 +1,5 @@ name: speculate-version: 0.2.3+version: 0.2.4 synopsis: discovery of properties about Haskell functions description: Speculate automatically discovers laws about Haskell functions.@@ -31,7 +31,7 @@ source-repository this type: git location: https://github.com/rudymatela/speculate- tag: v0.2.3+ tag: v0.2.4 library
src/Test/Speculate.hs view
@@ -1,4 +1,10 @@--- | __ Speculate: discovery of properties by reasoning from test results __+-- |+-- Module : Test.Speculate+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- __ Speculate: discovery of properties by reasoning from test results __ -- -- Speculate automatically discovers laws about Haskell functions. -- Those laws involve:
src/Test/Speculate/Args.hs view
@@ -1,3 +1,13 @@+{-# Language DeriveDataTypeable #-} -- for GHC <= 7.8+-- |+-- Module : Test.Speculate.CondReason+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part o Speculate.+--+-- Arguments to the 'speculate' function and parsing of command line arguments. module Test.Speculate.Args ( Args (..) , args@@ -68,6 +78,7 @@ , showDot :: Bool -- ^ __(advanced)__ whether to show a Graphviz dotfile with an Ord lattice , quietDot :: Bool -- ^ __(advanced)__ whether to show a Graphviz dotfiel with an Ord lattice (less verbose) }+ deriving Typeable -- for GHC <= 7.8 -- TODO: future options: --, closureLimit :: Int --, order :: OptOrder -- data OptOrder = Dershowitz | KnuthBendix@@ -161,11 +172,11 @@ && boolTy `elem` map (finalResultTy . typ) (allConstants args) atoms :: Args -> [Expr]-atoms args = map holeOfTy ts+atoms args = nubSort (map holeOfTy ts) `union` allConstants args `union` [showConstant True | showConds || showDot args] `union` [showConstant False | showConds || showDot args]- `union` catMaybes [eqE (computeInstances args) t | t <- ts, showConds]+ `union` (nubSort . catMaybes) [eqE (computeInstances args) t | t <- ts, showConds] where ts = types args showConds = reallyShowConditions args
src/Test/Speculate/CondReason.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.CondReason+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part o Speculate.+--+-- Conditional equational reasoning. module Test.Speculate.CondReason where import Test.Speculate.Expr@@ -5,7 +14,8 @@ import qualified Test.Speculate.Utils.Digraph as D import Test.Speculate.Utils.Digraph (Digraph) import Data.Maybe (mapMaybe,maybeToList,fromMaybe)-import Data.List (lookup)+import Data.List (lookup, sortBy)+import Data.Function (on) import Data.Functor ((<$>)) -- for GHC < 7.10 import qualified Data.List as L import Test.Speculate.Utils@@ -128,7 +138,7 @@ finalCondEquations :: ((Expr,Expr,Expr) -> Bool) -> Chy -> [(Expr,Expr,Expr)] finalCondEquations shouldShow =- sortOn (typ . (\(c,x,y) -> x))+ sortBy (compareTy `on` (\(c,x,y) -> typ x)) . filter shouldShow . cequations . cfinalize
src/Test/Speculate/Engine.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Engine+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Main engine to process data. module Test.Speculate.Engine ( vassignments , expansions
src/Test/Speculate/Expr.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Expr+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Utilities for manipulating expressions. module Test.Speculate.Expr ( module Test.Speculate.Expr.Core , module Test.Speculate.Expr.Ground
src/Test/Speculate/Expr/Canon.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Expr.Canon+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Canonicalize and check canonicity of expressions. module Test.Speculate.Expr.Canon ( canonicalize , canonicalizeWith
src/Test/Speculate/Expr/Core.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Expr.Core+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Defines the 'Expr' type and basic operations on it. module Test.Speculate.Expr.Core ( Expr (..) -- * Smart constructors@@ -202,9 +211,6 @@ _ `cmp` Var _ _ = GT Var _ _ `cmp` _ = LT -- Var < Constants < Apps--compareTy :: TypeRep -> TypeRep -> Ordering-compareTy = (compare `on` tyArity) <> compare lexicompareConstants :: Expr -> Expr -> Ordering lexicompareConstants = cmp
src/Test/Speculate/Expr/Equate.hs view
@@ -1,10 +1,18 @@--- | This module exports--- smart constructors,--- smart destructors--- and queries over--- equations,--- inequations--- and conditional equations.+-- |+-- Module : Test.Speculate.Expr.Equate+-- Copyright : (c) 2016-2017 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+-- smart constructors,+-- smart destructors+-- and queries over+-- equations,+-- inequations+-- and conditional equations. module Test.Speculate.Expr.Equate ( equation, unEquation, isEquation, uselessEquation, usefulEquation , phonyEquation
src/Test/Speculate/Expr/Ground.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Expr.Ground+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Generate and evaluate ground values of expressions. module Test.Speculate.Expr.Ground ( grounds , groundBinds
src/Test/Speculate/Expr/Match.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Expr.Match+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Matching expressions. module Test.Speculate.Expr.Match ( Binds -- * Assigning
src/Test/Speculate/Expr/TypeInfo.hs view
@@ -1,3 +1,13 @@+{-# Language DeriveDataTypeable, StandaloneDeriving #-} -- for GHC <= 7.8+-- |+-- Module : Test.Speculate.Expr.TypeInfo+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Typeclass instance information. module Test.Speculate.Expr.TypeInfo ( Instances , Instance (..)@@ -196,6 +206,8 @@ where m (Ord t' le _) | t == t' = Just le m _ = Nothing++deriving instance Typeable Word2 -- for GHC <= 7.8 -- TODO: include *ALL* prelude types on basicInstances preludeInstances :: Instances
src/Test/Speculate/Misc.hs view
@@ -1,5 +1,13 @@--- | Miscellaneous functions I still did not find a reasonable place to put--- them in.+-- |+-- Module : Test.Speculate.Misc+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part o Speculate.+--+-- Miscellaneous functions I still did not find a reasonable place to put+-- them in. module Test.Speculate.Misc ( functions1 , functions2
src/Test/Speculate/Pretty.hs view
@@ -1,4 +1,12 @@--- | Pretty printing of Equations, Inequalities and Conditional Equations+-- |+-- Module : Test.Speculate.Pretty+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Pretty printing of Equations, Inequalities and Conditional Equations module Test.Speculate.Pretty ( prettyThy, prettyEquations , prettyShy, prettySemiEquations
src/Test/Speculate/Reason.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Reason+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Equational reasoning for 'Expr's based on term rewriting. module Test.Speculate.Reason ( Thy (..) , emptyThy@@ -39,7 +48,6 @@ , defaultKeep , reductions1- , reductionsO , dwoBy , (|>)@@ -164,7 +172,7 @@ reduceRoot e (e1,e2) = (e2 `assigning`) <$> (e `match` e1) -- Lists all reductions by one rule, note that reductions may be repeated.--- For unrepeated reductions see reductionsO+-- @nub . sort@ to remove repetitions reductions1 :: Expr -> Rule -> [Expr] reductions1 e (l,_) | lengthE l > lengthE e = [] -- optional optimization reductions1 e@(e1 :$ e2) r = maybeToList (e `reduceRoot` r)@@ -172,15 +180,6 @@ ++ map (e1 :$) (reductions1 e2 r) reductions1 e r = maybeToList (e `reduceRoot` r) --- Lists all reductions by one rule without repetitions.--- For a faster version that allows repetitions, see reductions1-reductionsO :: Expr -> Rule -> [Expr]-reductionsO e (l,_) | lengthE l > lengthE e = [] -- optional optimization-reductionsO e@(e1 :$ e2) r = maybeToList (e `reduceRoot` r)- +++ map (:$ e2) (reductionsO e1 r)- +++ map (e1 :$) (reductionsO e2 r)-reductionsO e r = maybeToList (e `reduceRoot` r)- -- as defined by Martin & Nipkow in "Ordered Rewriting and Confluence" on 1990 -- this definition is sound, but incomplete (some groundJoinable pairs won't be -- detected).@@ -416,7 +415,8 @@ finalEquations :: (Equation -> Bool) -> Instances -> Thy -> [Equation] finalEquations shouldShow ti thy =- sortOn (typ . fst) . sortBy (compareE thy `on` uncurry phonyEquation)+ sortBy (compareTy `on` (typ . fst))+ . sortBy (compareE thy `on` uncurry phonyEquation) . filter shouldShow $ rules thy' ++ map swap (equations thy') where
src/Test/Speculate/Reason/Order.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Reason.Order+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part o Speculate.+--+-- Orders for term rewriting and completion. module Test.Speculate.Reason.Order ( (|>|) , (>|)
src/Test/Speculate/Report.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Report+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Report Speculate results. module Test.Speculate.Report ( report )
src/Test/Speculate/Sanity.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Sanity+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Sanity checks for before running the Speculate algorithm. module Test.Speculate.Sanity ( instanceErrors , eqOrdErrors
src/Test/Speculate/SemiReason.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Misc+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part o Speculate.+--+-- Inequational (or semi-equational) reasoning. module Test.Speculate.SemiReason where import Test.Speculate.Expr@@ -83,7 +92,7 @@ finalSemiEquations :: (Equation -> Bool) -> Instances -> (Expr -> Expr -> Bool) -> Shy -> [Equation] finalSemiEquations shouldShow insts equivalentInstanceOf shy =- sortOn (typ . fst)+ sortBy (compareTy `on` (typ . fst)) . filter shouldShow . discardLater (equivalentInstanceOf `on` uncurry phonyEquation) . discard (transConsequence shy)
src/Test/Speculate/Utils.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Utils+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Exports utility functions of all utils sub-modules. module Test.Speculate.Utils ( module Test.Speculate.Utils.Misc , module Test.Speculate.Utils.PrettyPrint
src/Test/Speculate/Utils/Class.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Utils.Class+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- An equivalence class type and functions to manipulate it. module Test.Speculate.Utils.Class ( merge , mergesOn
src/Test/Speculate/Utils/Colour.hs view
@@ -1,4 +1,12 @@--- | Simple colour module.+-- |+-- Module : Test.Speculate.Utils.Tuple+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate+--+-- Simple colour module. module Test.Speculate.Utils.Colour ( Colour (RGB) , Color
src/Test/Speculate/Utils/Digraph.hs view
@@ -1,3 +1,8 @@+-- |+-- Module : Test.Speculate.Utils.Digraph+-- Copyright : (c) 2016 Colin Runciman+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br> module Test.Speculate.Utils.Digraph ( Digraph , empty
src/Test/Speculate/Utils/List.hs view
@@ -1,10 +1,19 @@ {-# LANGUAGE CPP #-}+-- |+-- Module : Test.Speculate.Utils.List+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Utilities for manipulating lists. module Test.Speculate.Utils.List ( pairsThat , count, counts, countsBy , firsts , nubSort, nubSortBy- , (+++), nubMerge, nubMergeBy, nubMergeOn, nubMerges, nubMergeMap+ , (+++), nubMerge, nubMergeBy, nubMergeOn, nubMerges, nubMergesBy, nubMergeMap , ordIntersect, ordIntersectBy , ordered, orderedBy, orderedOn, strictlyOrdered, strictlyOrderedOn , areAll, areAny@@ -78,9 +87,12 @@ ordIntersect = ordIntersectBy compare nubMerges :: Ord a => [[a]] -> [a]-nubMerges [] = []-nubMerges [xs] = xs-nubMerges xss = nubMerges yss `nubMerge` nubMerges zss+nubMerges = nubMergesBy compare++nubMergesBy :: Ord a => (a -> a -> Ordering) -> [[a]] -> [a]+nubMergesBy cmp [] = []+nubMergesBy cmp [xs] = xs+nubMergesBy cmp xss = nubMergeBy cmp (nubMerges yss) (nubMerges zss) where (yss,zss) = splitHalf xss splitHalf xs = splitAt (length xs `div` 2) xs
src/Test/Speculate/Utils/Memoize.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Utils.Memoize+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Memoization module. module Test.Speculate.Utils.Memoize ( memory, memory2 , memoryFor, memory2For
src/Test/Speculate/Utils/Misc.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Utils.Misc+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Miscellaneous utilities. module Test.Speculate.Utils.Misc where import Test.LeanCheck
src/Test/Speculate/Utils/Ord.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Utils.Ord+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Utilities for manipulating 'Ordering' values. module Test.Speculate.Utils.Ord ( module Data.Ord , compareIndex
src/Test/Speculate/Utils/PrettyPrint.hs view
@@ -1,4 +1,12 @@--- | A very simple pretty printing library+-- |+-- Module : Test.Speculate.Utils.PrettyPrint+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- A very simple pretty printing library module Test.Speculate.Utils.PrettyPrint ( beside , above
src/Test/Speculate/Utils/String.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Utils.String+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Utilities for manipulating strings. module Test.Speculate.Utils.String ( module Data.String , module Data.Char
src/Test/Speculate/Utils/Tiers.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Utils.Tiers+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Utilities for manipulating tiers of values (of the 'Listable' typeclass). module Test.Speculate.Utils.Tiers ( productsList , mapTMaybe
src/Test/Speculate/Utils/Timeout.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Utils.Timeout+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Evaluate values to WHNF until a timeout. module Test.Speculate.Utils.Timeout ( timeoutToNothing , fromTimeout
src/Test/Speculate/Utils/Tuple.hs view
@@ -1,3 +1,8 @@+-- |+-- Module : Test.Speculate.Utils.Tuple+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br> module Test.Speculate.Utils.Tuple ( module Data.Tuple , fst3, fst4
src/Test/Speculate/Utils/Typeable.hs view
@@ -1,3 +1,12 @@+-- |+-- Module : Test.Speculate.Utils.Typeable+-- Copyright : (c) 2016-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- This module is part of Speculate.+--+-- Utilities to manipulate 'TypeRep's (of 'Typeable' values). module Test.Speculate.Utils.Typeable ( tyArity , typesIn@@ -9,12 +18,30 @@ , boolTy , mkEqnTy , funTyCon+ , compareTy , module Data.Typeable ) where import Data.Typeable+import Data.Monoid ((<>)) import Test.Speculate.Utils.List ((+++))++-- Different versions of Typeable/GHC provide different orderings for TypeReps.+-- The following is a version independent ordering, with the following+-- properties:+--+-- * functional types with more arguments are larger;+-- * type constructors with more arguments are larger.+compareTy :: TypeRep -> TypeRep -> Ordering+compareTy t1 t2 | t1 == t2 = EQ -- optional optimization+compareTy t1 t2 = tyArity t1 `compare` tyArity t2+ <> length ts1 `compare` length ts2+ <> show c1 `compare` show c2+ <> foldr (<>) EQ (zipWith compareTy ts1 ts2)+ where+ (c1,ts1) = splitTyConApp t1+ (c2,ts2) = splitTyConApp t2 tyArity :: TypeRep -> Int tyArity t
tests/test-expr.hs view
@@ -1,3 +1,4 @@+{-# Language DeriveDataTypeable, StandaloneDeriving #-} -- Travis {-# LANGUAGE CPP #-} -- Test library import Test@@ -6,11 +7,17 @@ -- Functions under test import Test.Speculate.Expr import Test.Speculate.Utils+import Test.Speculate.Reason (emptyThy) import Data.List (sort) import Data.Functor ((<$>)) -- for GHC < 7.10 import Data.Typeable (typeOf) import Data.Maybe (isJust) +-- for Travis:+deriving instance Typeable Thyght+deriving instance Typeable Equation+deriving instance Typeable Expr+ main :: IO () main = mainTest tests 10000 @@ -67,6 +74,21 @@ , absE < timesE , aa < ordE , ordE < timesE++ -- precedent types+ , pp < xx+ , cc < xx+ , pp < cc+ , xx < xxs+ , aa < zero+ , Test.true < zero+ , Test.true < aa+ , zero < ll++ -- further precedent types+ , constant "xx" xx < zero+ , constant "xxeqxx" (Equation xx xx) < constant "xx" xx+ , constant "xx" xx < constant "emptyThyght" (Thyght emptyThy) , unfoldApp (abs' xx) == [absE, xx] , unfoldApp (abs' (xx -+- yy)) == [absE, xx -+- yy]