Commits

Bryan O'Sullivan  committed 5336ef0

Finally! A test suite!

Admittedly containing just one test, but it's a start.

  • Participants
  • Parent commits d4a608f

Comments (0)

Files changed (3)

File criterion.cabal

 homepage:       https://github.com/bos/criterion
 bug-reports:    https://github.com/bos/criterion/issues
 build-type:     Simple
-cabal-version:  >= 1.6
+cabal-version:  >= 1.8
 extra-source-files:
   README.markdown
   examples/*.hs
   if impl(ghc >= 6.8)
     ghc-options: -fwarn-tabs
 
+test-suite tests
+  type:           exitcode-stdio-1.0
+  hs-source-dirs: tests
+  main-is:        Tests.hs
+
+  ghc-options:
+    -Wall -threaded -O0 -rtsopts
+
+  build-depends:
+    QuickCheck >= 2.4,
+    base,
+    criterion,
+    statistics,
+    test-framework >= 0.4,
+    test-framework-quickcheck2 >= 0.2,
+    vector
+
 source-repository head
   type:     git
   location: git://github.com/bos/criterion.git

File tests/Properties.hs

+{-# OPTIONS_GHC -fno-warn-orphans #-}
+
+module Properties (tests) where
+
+import Control.Applicative ((<$>))
+import Criterion.Analysis
+import Data.Monoid ((<>))
+import Statistics.Types (Sample)
+import Test.Framework (Test, testGroup)
+import Test.Framework.Providers.QuickCheck2 (testProperty)
+import Test.QuickCheck
+import qualified Data.Vector.Generic as G
+import qualified Data.Vector.Unboxed as U
+
+instance (Arbitrary a, U.Unbox a) => Arbitrary (U.Vector a) where
+  arbitrary = U.fromList <$> arbitrary
+  shrink    = map U.fromList . shrink . U.toList
+
+outlier_bucketing :: Sample -> Bool
+outlier_bucketing xs =
+  countOutliers (classifyOutliers xs) <= fromIntegral (G.length xs)
+
+outlier_bucketing_weighted :: Sample -> Bool
+outlier_bucketing_weighted xs =
+  outlier_bucketing (xs <> G.replicate (G.length xs * 10) 0)
+
+tests :: Test
+tests = testGroup "Properties" [
+    testProperty "outlier_bucketing" outlier_bucketing
+  , testProperty "outlier_bucketing_weighted" outlier_bucketing_weighted
+  ]

File tests/Tests.hs

+module Main (main) where
+
+import Test.Framework (defaultMain)
+
+import Properties
+
+main :: IO ()
+main = defaultMain [Properties.tests]