Commits

Bryan O'Sullivan committed 00663ae

Add a Cabal-ified test suite. Bump version to 1.2.6.9.

  • Participants
  • Parent commits 45949c5

Comments (0)

Files changed (4)

File bloomfilter.cabal

 name:            bloomfilter
-version:         1.2.6.8
+version:         1.2.6.9
 license:         BSD3
 license-file:    LICENSE
 author:          Bryan O'Sullivan <bos@serpentine.com>
 category:        Data
 stability:       provisional
 build-type:      Simple
-cabal-version:   >= 1.6
+cabal-version:   >= 1.8
 extra-source-files: README.markdown cbits/lookup3.c cbits/lookup3.h
                  examples/Makefile examples/SpellChecker.hs examples/Words.hs
 
   includes:         lookup3.h
   install-includes: lookup3.h
 
+test-suite tests
+  type:           exitcode-stdio-1.0
+  hs-source-dirs: tests
+  main-is:        QC.hs
+  other-modules:  QCSupport
+  build-depends:
+    QuickCheck == 2.4.*,
+    base < 5,
+    bloomfilter,
+    bytestring,
+    random,
+    test-framework,
+    test-framework-quickcheck2
+  if impl(ghc >= 6.10)
+    build-depends:
+      base >= 4
+
 source-repository head
   type:     git
   location: git://github.com/bos/bloomfilter.git

File tests/Makefile

-count := 1000
-
-all: test-$(count).out timing
-
-QC: QC.hs QCSupport.hs
-	ghc -package QuickCheck-1.2.0.0 -Wall -O -o $@ --make $<
-
-test-$(count).out: QC
-	./QC $(count) | tee test-$(count).out
-
-timing: hash_time HashTime
-
-hash_time: hash_time.c ../cbits/lookup3.c
-	$(CC) -I ../cbits -O3 -o $@ $^
-
-HashTime: HashTime.hs
-	ghc -O3 -o $@ --make $^
-
-clean:
-	-rm -f QC hash_time HashTime *.hi *.o test-[0-9]*.out
 import qualified Data.ByteString.Lazy.Char8 as LB
 import Data.Int (Int8, Int16, Int32, Int64)
 import Data.Word (Word8, Word16, Word32, Word64)
-import System.Environment (getArgs)
+import Test.Framework.Providers.QuickCheck2 (testProperty)
 import System.IO (BufferMode(..), hSetBuffering, stdout)
+import Test.Framework (Test, defaultMain)
 import Test.QuickCheck (Property, Testable, (==>), choose, forAll)
 
-import QCSupport (P(..), limCheck)
+import QCSupport (P(..))
 
-prop_pai :: (Hashable a) => a -> (a, P) -> Bool
-prop_pai _ (xs, P q) = let bf = easyList q [xs] in xs `elemB` bf
+prop_pai :: (Hashable a) => a -> a -> P -> Bool
+prop_pai _ xs (P q) = let bf = easyList q [xs] in xs `elemB` bf
 
-p :: Testable a => String -> a -> (Int -> IO (), String)
-p desc prop = (\count -> limCheck count prop, desc)
-
-tests :: [(Int -> IO (), String)]
+tests :: [Test]
 tests = [
-   p "()" $ prop_pai ()
- , p "Bool" $ prop_pai (undefined :: Bool)
- , p "Ordering" $ prop_pai (undefined :: Ordering)
- , p "Char" $ prop_pai (undefined :: Char)
- , p "Int" $ prop_pai (undefined :: Int)
- , p "Float" $ prop_pai (undefined :: Float)
- , p "Double" $ prop_pai (undefined :: Double)
- , p "Int8" $ prop_pai (undefined :: Int8)
- , p "Int16" $ prop_pai (undefined :: Int16)
- , p "Int32" $ prop_pai (undefined :: Int32)
- , p "Int64" $ prop_pai (undefined :: Int64)
- , p "Word8" $ prop_pai (undefined :: Word8)
- , p "Word16" $ prop_pai (undefined :: Word16)
- , p "Word32" $ prop_pai (undefined :: Word32)
- , p "Word64" $ prop_pai (undefined :: Word64)
- , p "String" $ prop_pai (undefined :: String)
- , p "LB.ByteString" $ prop_pai (undefined :: LB.ByteString)
- , p "prop_rechunked_eq" prop_rechunked_eq
+   testProperty "()" $ prop_pai ()
+ , testProperty "Bool" $ prop_pai (undefined :: Bool)
+ , testProperty "Ordering" $ prop_pai (undefined :: Ordering)
+ , testProperty "Char" $ prop_pai (undefined :: Char)
+ , testProperty "Int" $ prop_pai (undefined :: Int)
+ , testProperty "Float" $ prop_pai (undefined :: Float)
+ , testProperty "Double" $ prop_pai (undefined :: Double)
+ , testProperty "Int8" $ prop_pai (undefined :: Int8)
+ , testProperty "Int16" $ prop_pai (undefined :: Int16)
+ , testProperty "Int32" $ prop_pai (undefined :: Int32)
+ , testProperty "Int64" $ prop_pai (undefined :: Int64)
+ , testProperty "Word8" $ prop_pai (undefined :: Word8)
+ , testProperty "Word16" $ prop_pai (undefined :: Word16)
+ , testProperty "Word32" $ prop_pai (undefined :: Word32)
+ , testProperty "Word64" $ prop_pai (undefined :: Word64)
+ , testProperty "String" $ prop_pai (undefined :: String)
+ , testProperty "LB.ByteString" $ prop_pai (undefined :: LB.ByteString)
+ , testProperty "prop_rechunked_eq" prop_rechunked_eq
  ]
 
 rechunk :: Int64 -> LB.ByteString -> LB.ByteString
 prop_rechunked_eq = prop_rechunked hash64
 
 main :: IO ()
-main = do
-  args <- getArgs
-  let limits = case args of
-                [] -> [100]
-                xs -> map read xs
-  hSetBuffering stdout NoBuffering
-  forM_ limits $ \limit ->
-    forM_ tests $ \(test, desc) -> do
-      putStr $ desc ++ ": "
-      test limit
+main = defaultMain tests

File tests/QCSupport.hs

 module QCSupport
     (
       P(..)
-    , limCheck
     ) where
 
 import Data.Int (Int8, Int16, Int32, Int64)
 import System.Random (Random(..), RandomGen)
 import Test.QuickCheck
 
-limCheck :: Testable a => Int -> a -> IO ()
-limCheck limit = check defaultConfig {
-                   configMaxTest = limit
-                 , configEvery = \_ _ -> ""
-                 }
-
 newtype P = P { unP :: Double }
     deriving (Eq, Ord, Show, Fractional, Num, Random)
 
 instance Arbitrary P where
     arbitrary = choose (epsilon, 1 - epsilon)
         where epsilon = 1e-6 :: P
-    coarbitrary = coarbitrary . decodeFloat . unP
 
 instance Arbitrary Ordering where
     arbitrary = oneof [return LT, return GT, return EQ]
-    coarbitrary = coarbitrary . fromEnum
-
-instance Arbitrary Char where
-    arbitrary = choose (minBound, maxBound)
-    coarbitrary = coarbitrary . fromEnum
 
 integralRandomR :: (Integral a, RandomGen g) => (a, a) -> g -> (a, g)
 integralRandomR (a,b) g = case randomR (fromIntegral a :: Int,
                                         fromIntegral b :: Int) g
                           of (x,g') -> (fromIntegral x, g')
 
-instance Random Int8 where
-  randomR = integralRandomR
-  random = randomR (minBound,maxBound)
-
-instance Random Int16 where
-  randomR = integralRandomR
-  random = randomR (minBound,maxBound)
-
-instance Random Int32 where
-  randomR = integralRandomR
-  random = randomR (minBound,maxBound)
-
 instance Random Int64 where
   randomR = integralRandomR
   random = randomR (minBound,maxBound)
 
-instance Random Word8 where
-  randomR = integralRandomR
-  random = randomR (minBound,maxBound)
-
-instance Random Word16 where
-  randomR = integralRandomR
-  random = randomR (minBound,maxBound)
-
-instance Random Word32 where
-  randomR = integralRandomR
-  random = randomR (minBound,maxBound)
-
-instance Random Word64 where
-  randomR = integralRandomR
-  random = randomR (minBound,maxBound)
-
-integralCoarbitrary :: (Integral a) => a -> Gen b -> Gen b
-integralCoarbitrary n = variant (if n' >= 0 then 2*n' else 2*(-n') + 1)
-        where n' = fromIntegral n
-
-instance Arbitrary Int8 where
-    arbitrary = choose (minBound, maxBound)
-    coarbitrary = integralCoarbitrary
-
-instance Arbitrary Int16 where
-    arbitrary = choose (minBound, maxBound)
-    coarbitrary = integralCoarbitrary
-
-instance Arbitrary Int32 where
-    arbitrary = choose (minBound, maxBound)
-    coarbitrary = integralCoarbitrary
-
-instance Arbitrary Int64 where
-    arbitrary = choose (minBound, maxBound)
-    coarbitrary = integralCoarbitrary
-
-instance Arbitrary Word8 where
-    arbitrary = choose (minBound, maxBound)
-    coarbitrary = integralCoarbitrary
-
-instance Arbitrary Word16 where
-    arbitrary = choose (minBound, maxBound)
-    coarbitrary = integralCoarbitrary
-
-instance Arbitrary Word32 where
-    arbitrary = choose (minBound, maxBound)
-    coarbitrary = integralCoarbitrary
-
-instance Arbitrary Word64 where
-    arbitrary = choose (minBound, maxBound)
-    coarbitrary = integralCoarbitrary
-
 instance Arbitrary LB.ByteString where
     arbitrary = sized $ \n -> resize (round (sqrt (toEnum n :: Double)))
                 ((LB.fromChunks . filter (not . SB.null)) `fmap` arbitrary)
-    coarbitrary = coarbitrary . LB.unpack
 
 instance Arbitrary SB.ByteString where
     arbitrary = SB.pack `fmap` arbitrary
-    coarbitrary = coarbitrary . SB.unpack