packages feed

speculate 0.3.0 → 0.3.1

raw patch · 4 files changed

+23/−6 lines, 4 files

Files

speculate.cabal view
@@ -1,5 +1,5 @@ name:                speculate-version:             0.3.0+version:             0.3.1 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.3.0+  tag:             v0.3.1   library
src/Test/Speculate/Reason.hs view
@@ -172,7 +172,6 @@ reduceRoot e (e1,e2) = (e2 `assigning`) <$> (e `match` e1)  -- Lists all reductions by one rule, note that reductions may be repeated.--- @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)
src/Test/Speculate/Utils/List.hs view
@@ -31,6 +31,7 @@   , accum   , partitionByMarkers   , (!)+  , halve   ) where @@ -54,11 +55,20 @@ firsts [] = [] firsts (x:xs) = x : firsts (filter (/= x) xs) +halve :: [a] -> ([a],[a])+halve [] = ([],[])+halve xs = (take h xs, drop h xs)+  where+  h = length xs `div` 2+ nubSort :: Ord a => [a] -> [a]-nubSort = nub . sort+nubSort = nubSortBy compare  nubSortBy :: (a -> a -> Ordering) -> [a] -> [a]-nubSortBy cmp = nubBy (\x y -> x `cmp` y == EQ) . sortBy cmp+nubSortBy cmp xs  =+  case halve xs of+  ([],zs) -> zs+  (ys,zs) -> nubMergeBy cmp (nubSortBy cmp ys) (nubSortBy cmp zs)  nubMergeBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a] nubMergeBy cmp (x:xs) (y:ys) = case x `cmp` y of@@ -186,7 +196,7 @@               | otherwise      = d (xs++[y]) ys  allUnique :: Ord a => [a] -> Bool-allUnique xs = nub (sort xs) == sort xs+allUnique xs = nubSort xs == sort xs  chain :: [a -> a] -> a -> a chain = foldr (.) id
tests/test-utils.hs view
@@ -127,6 +127,14 @@   , holds n $ \xs ys -> strictlyOrdered xs && strictlyOrdered ys                     ==> xs +++ ys == nubSort (xs ++ ys :: [Int]) +  , holds n $ nubSort === nub . sort -:> [int]++  , halve []        == ([],[]::[Int])+  , halve [1]       == ([],[1])+  , halve [1,2]     == ([1],[2])+  , halve [1,2,3]   == ([1],[2,3])+  , halve [1,2,3,4] == ([1,2],[3,4])+   , holds n $ \n xss -> 0 <  n && n <  length xss ==> xss ! n == (xss !! n :: [Int])   , holds n $ \n xss -> 0 >= n && n >= length xss ==> xss ! n == ([] :: [Int])   ]