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

Make test deps optional in the library #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Data/Ranged/Boundaries.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE CPP #-}

-----------------------------------------------------------------------------
-- |
-- Module : Data.Ranged.Boundaries
Expand All @@ -20,7 +22,10 @@ module Data.Ranged.Boundaries (
) where

import Data.Ratio

#ifdef WITH_TESTS
import Test.QuickCheck
#endif

infix 4 />/

Expand Down Expand Up @@ -210,6 +215,7 @@ instance (DiscreteOrdered a) => Ord (Boundary a) where
BoundaryBelowAll -> EQ
_ -> LT

#ifdef WITH_TESTS
-- QuickCheck Generator

instance Arbitrary a => Arbitrary (Boundary a) where
Expand All @@ -227,3 +233,4 @@ instance CoArbitrary a => CoArbitrary (Boundary a) where
coarbitrary (BoundaryBelow v) = variant (2 :: Int) . coarbitrary v
coarbitrary (BoundaryAbove v) = variant (3 :: Int) . coarbitrary v

#endif
11 changes: 11 additions & 0 deletions Data/Ranged/RangedSet.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE CPP #-}

module Data.Ranged.RangedSet (
-- ** Ranged Set Type
RSet,
Expand All @@ -23,6 +25,8 @@ module Data.Ranged.RangedSet (
-- ** Useful Sets
rSetEmpty,
rSetFull,

#ifdef WITH_TESTS
-- ** QuickCheck Properties
-- *** Construction
prop_validNormalised,
Expand Down Expand Up @@ -54,13 +58,17 @@ module Data.Ranged.RangedSet (
prop_union_associates,
prop_de_morgan_intersection,
prop_de_morgan_union,
#endif
) where

import Data.Ranged.Boundaries
import Data.Ranged.Ranges

import Data.List

#ifdef WITH_TESTS
import Test.QuickCheck
#endif

infixl 7 -/\-
infixl 6 -\/-, -!-
Expand Down Expand Up @@ -246,6 +254,7 @@ rSetUnfold bound upperFunc succFunc = RSet $ normalise $ ranges1 bound
Nothing -> []


#ifdef WITH_TESTS
-- QuickCheck Generators

instance (Arbitrary v, DiscreteOrdered v, Show v) =>
Expand Down Expand Up @@ -485,3 +494,5 @@ prop_de_morgan_intersection rs1 rs2 =
prop_de_morgan_union :: (DiscreteOrdered a) => RSet a -> RSet a -> Bool
prop_de_morgan_union rs1 rs2 =
rSetNegation (rs1 -\/- rs2) == (rSetNegation rs1 -/\- rSetNegation rs2)

#endif
13 changes: 11 additions & 2 deletions Data/Ranged/Ranges.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE CPP #-}

-----------------------------------------------------------------------------
--
-- Module : Data.Ranged.Ranges
Expand Down Expand Up @@ -29,6 +31,8 @@ module Data.Ranged.Ranges (
rangeIntersection,
rangeUnion,
rangeDifference,

#ifdef WITH_TESTS
-- ** QuickCheck properties
prop_unionRange,
prop_unionRangeLength,
Expand All @@ -42,13 +46,17 @@ module Data.Ranged.Ranges (
prop_emptyNonSingleton,
prop_fullNonSingleton,
prop_nonSingleton,
prop_intSingleton
prop_intSingleton,
#endif
) where

import Control.Monad
import Data.Ranged.Boundaries
import Data.Maybe

#ifdef WITH_TESTS
import Test.QuickCheck
#endif

-- | A Range has upper and lower boundaries.
data Ord v => Range v = Range {rangeLower, rangeUpper :: Boundary v}
Expand Down Expand Up @@ -213,6 +221,7 @@ rangeDifference r1@(Range lower1 upper1) (Range lower2 upper2) =
intersects = (max lower1 lower2) < (min upper1 upper2)


#ifdef WITH_TESTS
-- QuickCheck generators

instance (Arbitrary v, DiscreteOrdered v, Show v) =>
Expand Down Expand Up @@ -356,4 +365,4 @@ prop_intSingleton x y = forAll (rangeAround x y) $ \r ->
rangeAround v1 v2 = return Range `ap` genBound v1 `ap` genBound v2
genBound v = elements [BoundaryAbove v, BoundaryBelow v]


#endif
12 changes: 10 additions & 2 deletions Ranged-sets.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ category: Data
author: Paul Johnson
extra-source-files: CHANGES.txt README.txt

flag with-tests
description: Include unit tests / extra instances.
default: True
manual: False

library
build-depends: HUnit -any, QuickCheck >=2, base >=4.11 && <5
build-depends: base >=4.11 && <5
if flag(with-tests)
ghc-options: -DWITH_TESTS
build-depends: QuickCheck >=2
exposed-modules: Data.Ranged Data.Ranged.Ranges
Data.Ranged.RangedSet Data.Ranged.Boundaries
exposed: True
Expand All @@ -36,10 +44,10 @@ Test-suite properties
default-language: Haskell2010
main-is: Main.hs
hs-source-dirs: tests .
cpp-options: -DWITH_TESTS
other-modules: Data.Ranged Data.Ranged.Ranges
Data.Ranged.RangedSet Data.Ranged.Boundaries
build-depends:
base >= 4 && < 5,
HUnit,
QuickCheck