packages feed

pqc 0.3 → 0.4

raw patch · 3 files changed

+91/−17 lines, 3 filesdep +pqcdep ~basePVP ok

version bump matches the API change (PVP)

Dependencies added: pqc

Dependency ranges changed: base

API changes (from Hackage documentation)

- Test.QuickCheck.Parallel: pDet :: Testable a => a -> Int -> IO String
+ Test.QuickCheck.Parallel: pDet :: Testable a => a -> Int -> IO Result
- Test.QuickCheck.Parallel: pNon :: Testable a => a -> Int -> IO String
+ Test.QuickCheck.Parallel: pNon :: Testable a => a -> Int -> IO Result

Files

Test/QuickCheck/Parallel.hs view
@@ -37,12 +37,13 @@ #endif import Control.Monad      (forM_, unless) import System.Random+import System.Exit import System.IO          (hFlush,stdout) import Text.Printf  type Name   = String type Depth  = Int-type Test   = (Name, Depth -> IO String)+type Test   = (Name, Depth -> IO Result)  -- | Deprecated: Backwards-compatible API {-# DEPRECATED pRun "use pRun' or pRunAllProcessors, pRunWithNum instead." #-}@@ -94,8 +95,9 @@     chan <- newChan     ps   <- getChanContents chan     work <- newMVar tests+    ec'  <- newMVar ExitSuccess -    forM_ [1..n] $ forkIO . thread work chan+    forM_ [1..n] $ forkIO . thread work chan ec'      let wait xs i             | i >= n    = return () -- done@@ -103,10 +105,12 @@                     Nothing : ys -> wait ys $! i+1                     Just s  : ys -> putStr s >> hFlush stdout >> wait ys i     wait ps 0+    ec <- takeMVar ec'+    exitWith ec    where-    thread :: MVar [Test] -> Chan (Maybe String) -> Int -> IO ()-    thread work chan me = loop+    thread :: MVar [Test] -> Chan (Maybe String) -> (MVar ExitCode) -> Int -> IO ()+    thread work chan ec' me = loop       where         loop = do             job <- modifyMVar work $ \jobs -> return $ case jobs of@@ -116,20 +120,23 @@                 Nothing          -> writeChan chan Nothing -- done                 Just (name,prop) -> do                     v <- prop depth-                    writeChan chan . Just $ printf "%d: %-25s: %s" me name v+                    doesAnyFailureTest v ec'+                    writeChan chan . Just $ printf "%d: %-25s: %s" me name $ output v                     loop+    doesAnyFailureTest :: Result -> MVar (ExitCode) -> IO ()+    doesAnyFailureTest v ec'+      = case v of+          (GaveUp _ _ _)          -> modifyMVar_ ec' (\_ -> return $ ExitFailure 1)+          (Failure _ _ _ _ _ _ _) -> modifyMVar_ ec' (\_ -> return $ ExitFailure 1)+          _                       -> return ()  -- | Wrap a property, and run it on a deterministic set of data-pDet :: Testable a => a -> Int -> IO String-pDet a n =-  do result <- mycheck Det (stdArgs { maxSuccess = n }) a-     return $ output result+pDet :: Testable a => a -> Int -> IO Result+pDet a n = mycheck Det (stdArgs { maxSuccess = n }) a  -- | Wrap a property, and run it on a non-deterministic set of data-pNon :: Testable a => a -> Int -> IO String-pNon a n =-  do result <- mycheck NonDet (stdArgs { maxSuccess = n }) a-     return $ output result+pNon :: Testable a => a -> Int -> IO Result+pNon a n = mycheck NonDet (stdArgs { maxSuccess = n }) a  data Mode = Det | NonDet 
+ examples/Example.hs view
@@ -0,0 +1,52 @@+-- +--+-- $ ghc -O -package pqc Example.hs -threaded+-- +--++import Test.QuickCheck.Parallel+import Data.List+import System.Environment++prop_sort1 xs = sort xs == sortBy compare xs+  where types = (xs :: [Int])++prop_sort2 xs =+        (not (null xs)) ==>+        (head (sort xs) == minimum xs)+  where types = (xs :: [Int])++prop_sort3 xs = (not (null xs)) ==>+        last (sort xs) == maximum xs+  where types = (xs :: [Int])++prop_sort4 xs ys =+        (not (null xs)) ==>+        (not (null ys)) ==>+        (head (sort (xs ++ ys)) == min (minimum xs) (minimum ys))+  where types = (xs :: [Int], ys :: [Int])++prop_sort6 xs ys =+        (not (null xs)) ==>+        (not (null ys)) ==>+        (last (sort (xs ++ ys)) == max (maximum xs) (maximum ys))+  where types = (xs :: [Int], ys :: [Int])++prop_sort5 xs ys =+        (not (null xs)) ==>+        (not (null ys)) ==>+        (head (sort (xs ++ ys)) == max (maximum xs) (maximum ys))+  where types = (xs :: [Int], ys :: [Int])++--+-- Run in 4 threads, to depth of 1000+--+main = do+    n <- getArgs >>= readIO . head+    pRun n 1000 $ take 100 $ cycle+        [ ("sort1", pDet prop_sort1)+        , ("sort2", pDet prop_sort2)+        , ("sort3", pDet prop_sort3)+        , ("sort4", pDet prop_sort4)+        , ("sort5", pDet prop_sort5)+        ]
pqc.cabal view
@@ -1,5 +1,5 @@ name:                pqc-version:             0.3+version:             0.4 description:         Parallel batch driver for QuickCheck synopsis:            Parallel batch driver for QuickCheck category:            Testing@@ -9,7 +9,7 @@ Maintainer:          shelarcy <shelarcy@gmail.com> homepage:            http://darcsden.com/shelarcy/pqc build-type: Simple-Cabal-Version: >= 1.6+Cabal-Version: >= 1.10  source-repository head    type: darcs@@ -22,5 +22,20 @@     build-depends:     base >= 3 && < 5, random, QuickCheck > 2.1 && < 3   else     build-depends:     base < 3, QuickCheck > 2.1 && < 3-  exposed-modules: Test.QuickCheck.Parallel-  ghc-options:    -Wall -O2+  default-language: Haskell2010+  exposed-modules:  Test.QuickCheck.Parallel+  ghc-options:      -Wall -O2++Test-Suite Example+  type:       exitcode-stdio-1.0+  main-is:    Example.hs+  buildable:       False+  hs-source-dirs:  examples+  default-language: Haskell2010+  build-depends:    base < 5, pqc+  -- for GHC 7.4.1 with pRunAllProcessors+  -- ghc-options:      -threaded+  -- for GHC 7.2.1 or higher+  -- ghc-options:      -threaded -with-rtsopts=-N+  -- for GHC 7.0.x+  ghc-options:      -threaded -rtsopts -with-rtsopts=-N