packages feed

utility-ht 0.0.7 → 0.0.7.1

raw patch · 8 files changed

+239/−2 lines, 8 files

Files

src/Data/Function/HT/Private.hs view
@@ -43,3 +43,12 @@  powerAssociative1 op a0 a n =    foldr op a0 (genericReplicate n a)+++infixl 0 $%++{- |+Flipped version of '($)'.+-}+($%) :: a -> (a -> b) -> b+($%) = flip ($)
+ src/Test.hs view
@@ -0,0 +1,21 @@+module Main where++import qualified Test.Data.List      as ListHT+import qualified Test.Data.ListMatch as ListMatch+import qualified Test.Data.Maybe     as MaybeHT+import qualified Test.Data.Function  as FunctionHT+++prefix :: String -> [(String, IO ())] -> [(String, IO ())]+prefix msg =+   map (\(str,test) -> (msg ++ "." ++ str, test))++main :: IO ()+main =+   mapM_ (\(msg,io) -> putStr (msg++": ") >> io) $+   concat $+      prefix "List"      ListHT.tests :+      prefix "ListMatch" ListMatch.tests :+      prefix "Maybe"     MaybeHT.tests :+      prefix "Function"  FunctionHT.tests :+      []
+ src/Test/Data/Function.hs view
@@ -0,0 +1,18 @@+module Test.Data.Function where++import qualified Data.Function.HT.Private as FuncHT++import Test.QuickCheck (Property, quickCheck, (==>), )+++powerAssociative :: Eq a =>+   (a -> a -> a) -> a -> a -> Integer -> Property+powerAssociative op a0 a n =+   n>0 ==>+      FuncHT.powerAssociative op a0 a n == FuncHT.powerAssociative1 op a0 a n+++tests :: [(String, IO ())]+tests =+   ("powerAssociative", quickCheck (powerAssociative (+) :: Integer -> Integer -> Integer -> Property)) :+   []
+ src/Test/Data/List.hs view
@@ -0,0 +1,81 @@+module Test.Data.List where++import qualified Data.List.HT.Private as ListHT+import qualified Data.List as List+import Control.Monad (liftM2, )++import Test.Utility (equalLists, equalInfLists, )+import Test.QuickCheck (Testable, Property, quickCheck, (==>), )++import Prelude hiding (iterate, )++++sieve :: Eq a => Int -> [a] -> Property+sieve n x =+   n>0 ==>+      equalLists [ListHT.sieve    n x,+                  ListHT.sieve'   n x,+                  ListHT.sieve''  n x,+                  ListHT.sieve''' n x]+++sliceHorizontal :: Eq a => Int -> [a] -> Bool+sliceHorizontal n0 x =+   let n = 1 + mod n0 1000+   in  ListHT.sliceHorizontal n x == ListHT.sliceHorizontal' n x+++sliceVertical :: Eq a => Int -> [a] -> Property+sliceVertical n x =+   n>0 ==>+      ListHT.sliceVertical n x == ListHT.sliceVertical' n x++slice :: Eq a => Int -> [a] -> a -> Bool+slice n0 as a =+   let x = a:as+       n = 1 + mod n0 (length x)+   in  -- problems: ListHT.sliceHorizontal 4 [] == [[],[],[],[]]+       ListHT.sliceHorizontal n x == List.transpose (ListHT.sliceVertical  n x)  &&+       ListHT.sliceVertical  n x == List.transpose (ListHT.sliceHorizontal n x)+++++shear :: Eq a => [[a]] -> Bool+shear xs =+   ListHT.shearTranspose xs  ==  map reverse (ListHT.shear xs)++++outerProduct :: (Eq a, Eq b) => [a] -> [b] -> Bool+outerProduct xs ys =+   concat (ListHT.outerProduct (,) xs ys)  ==  liftM2 (,) xs ys++++iterate :: Eq a => (a -> a -> a) -> a -> Bool+iterate op a =+   let xs = List.iterate (op a) a+       ys = ListHT.iterateAssociative op a+       zs = ListHT.iterateLeaky op a+   in  equalInfLists 1000 [xs, ys, zs]++++simple ::+   (Testable test) =>+   (Int -> [Integer] -> test) -> IO ()+simple = quickCheck+++tests :: [(String, IO ())]+tests =+   ("sieve",            simple sieve) :+   ("sliceHorizontal",  simple sliceHorizontal) :+   ("sliceVertical",    simple sliceVertical) :+   ("slice",            simple slice) :+   ("shear",            quickCheck (shear           :: [[Integer]] -> Bool)) :+   ("outerProduct",     quickCheck (outerProduct    :: [Integer] -> [Int] -> Bool)) :+   ("iterate",          quickCheck (iterate (+)     :: Integer -> Bool)) :+   []
+ src/Test/Data/ListMatch.hs view
@@ -0,0 +1,66 @@+module Test.Data.ListMatch where++import qualified Data.List.Match.Private as Match+import qualified Data.List as List++import Test.Utility (equalLists, )+import Test.QuickCheck (Testable, quickCheck, )++import Prelude hiding (iterate, take, drop, splitAt, )++++laxTail :: (Eq a) => [a] -> Bool+laxTail xs =+   Match.laxTail xs == Match.laxTail0 xs++take :: (Eq a) => [b] -> [a] -> Bool+take xs ys =+   Match.take xs ys == List.take (length xs) ys++drop :: (Eq a) => [b] -> [a] -> Bool+drop xs ys =+   Match.drop xs ys == List.drop (length xs) ys++dropAlt :: (Eq a) => [b] -> [a] -> Bool+dropAlt xs ys =+   equalLists $+      Match.drop xs ys :+      Match.drop0 xs ys :+      Match.drop1 xs ys :+      Match.drop2 xs ys :+      Match.dropRec xs ys :+      []++takeDrop :: (Eq a) => [b] -> [a] -> Bool+takeDrop xs ys =+   Match.take xs ys ++ Match.drop xs ys == ys++splitAt :: (Eq a) => [b] -> [a] -> Bool+splitAt xs ys =+   (Match.take xs ys, Match.drop xs ys) == Match.splitAt xs ys+++compareLength :: [a] -> [b] -> Bool+compareLength xs ys =+   Match.compareLength xs ys == Match.compareLength0 xs ys &&+   Match.compareLength xs ys == Match.compareLength1 xs ys+++test1 :: Testable test => ([Int] -> test) -> IO ()+test1 = quickCheck++test2 :: Testable test => ([Int] -> [Integer] -> test) -> IO ()+test2 = quickCheck+++tests :: [(String, IO ())]+tests =+   ("laxTail",          test1 laxTail) :+   ("take",             test2 take) :+   ("drop",             test2 drop) :+   ("dropAlt",          test2 dropAlt) :+   ("takeDrop",         test2 takeDrop) :+   ("splitAt",          test2 splitAt) :+   ("compareLength",    test2 compareLength) :+   []
+ src/Test/Data/Maybe.hs view
@@ -0,0 +1,17 @@+module Test.Data.Maybe where++import Control.Monad (guard, )+import Data.Maybe.HT (toMaybe, )++import Test.QuickCheck (quickCheck, )+++toMaybeGuard :: Eq a => Bool -> Maybe a -> Bool+toMaybeGuard b x =+   (guard b >> x)   ==   (toMaybe b =<< x)+++tests :: [(String, IO ())]+tests =+   ("toMaybeGuard", quickCheck (\b x -> toMaybeGuard b (x::Maybe Int))) :+   []
+ src/Test/Utility.hs view
@@ -0,0 +1,16 @@+-- cf. Test.NumericPrelude.Utility+module Test.Utility where++import Data.List.HT (mapAdjacent, )+import qualified Data.List as List+++-- compare the lists simultaneously+equalLists :: Eq a => [[a]] -> Bool+equalLists xs =+   let equalElems ys =+          and (mapAdjacent (==) ys)  &&  length xs == length ys+   in  all equalElems (List.transpose xs)++equalInfLists :: Eq a => Int -> [[a]] -> Bool+equalInfLists n xs = equalLists (map (take n) xs)
utility-ht.cabal view
@@ -1,5 +1,5 @@ Name:             utility-ht-Version:          0.0.7+Version:          0.0.7.1 License:          BSD3 License-File:     LICENSE Author:           Henning Thielemann <haskell@henning-thielemann.de>@@ -23,6 +23,15 @@ Cabal-Version:     >=1.10 Build-Type:        Simple +-- workaround for Cabal-1.10+Extra-Source-Files:+  src/Test/Data/Maybe.hs+  src/Test/Data/ListMatch.hs+  src/Test/Data/Function.hs+  src/Test/Data/List.hs+  src/Test/Utility.hs+  src/Test.hs+ Source-Repository head   type:     darcs   location: http://code.haskell.org/~thielema/utility/@@ -30,7 +39,7 @@ Source-Repository this   type:     darcs   location: http://code.haskell.org/~thielema/utility/-  tag:      0.0.7+  tag:      0.0.7.1  Library   Build-Depends: