Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add classifications to properties #253

Merged
merged 2 commits into from Apr 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions hedgehog-example/src/Test/Example/Coverage.hs
@@ -0,0 +1,40 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Test.Example.Coverage (
tests
) where

import Control.Concurrent (threadDelay)

import Data.Foldable (for_)

import Hedgehog
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range

prop_classify :: Property
prop_classify =
withTests 1 . property $ do
for_ [1 :: Int ..100] $ \a -> do
classify "small number" $ a < 50
classify "big number" $ a >= 50

prop_cover_number :: Property
prop_cover_number =
property $ do
number <- forAll (Gen.int $ Range.linear 1 100)
evalIO $ threadDelay 20000
cover 50 "small number" $ number < 50
cover 50 "medium number" $ number >= 20
cover 50 "big number" $ number >= 50

prop_cover_bool :: Property
prop_cover_bool =
property $ do
match <- forAll Gen.bool
cover 30 "True" match
cover 30 "False" $ not match

tests :: IO Bool
tests =
checkParallel $$(discover)
7 changes: 5 additions & 2 deletions hedgehog/src/Hedgehog.hs
Expand Up @@ -56,6 +56,8 @@ module Hedgehog (

, forAll
, forAllWith
, classify
, cover
, discard

, check
Expand Down Expand Up @@ -151,8 +153,9 @@ import Hedgehog.Internal.Distributive (Distributive(..))
import Hedgehog.Internal.Gen (Gen, GenT, MonadGen(..))
import Hedgehog.Internal.HTraversable (HTraversable(..))
import Hedgehog.Internal.Opaque (Opaque(..))
import Hedgehog.Internal.Property (assert, diff, annotate, annotateShow)
import Hedgehog.Internal.Property ((===), (/==))
import Hedgehog.Internal.Property (annotate, annotateShow)
import Hedgehog.Internal.Property (assert, diff, (===), (/==))
import Hedgehog.Internal.Property (classify, cover)
import Hedgehog.Internal.Property (discard, failure, success)
import Hedgehog.Internal.Property (DiscardLimit, withDiscards)
import Hedgehog.Internal.Property (eval, evalM, evalIO)
Expand Down