Permalink
Browse files

Finally! A test suite!

Admittedly containing just one test, but it's a start.
  • Loading branch information...
1 parent ea5cd9e commit f028c02e5ec26c5e24f626c2f53da936bbe926bf @bos committed Sep 11, 2013
Showing with 57 additions and 1 deletion.
  1. +18 −1 criterion.cabal
  2. +31 −0 tests/Properties.hs
  3. +8 −0 tests/Tests.hs
View
@@ -10,7 +10,7 @@ category: Development, Performance, Testing, Benchmarking
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
@@ -91,6 +91,23 @@ library
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
View
@@ -0,0 +1,31 @@
+{-# 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
+ ]
View
@@ -0,0 +1,8 @@
+module Main (main) where
+
+import Test.Framework (defaultMain)
+
+import Properties
+
+main :: IO ()
+main = defaultMain [Properties.tests]

0 comments on commit f028c02

Please sign in to comment.