packages feed

quickcheck-special (empty) → 0.1.0.0

raw patch · 4 files changed

+197/−0 lines, 4 filesdep +QuickCheckdep +basedep +bytestringsetup-changed

Dependencies added: QuickCheck, base, bytestring, nats, quickcheck-instances, scientific, text

Files

+ LICENSE view
@@ -0,0 +1,21 @@+The MIT License (MIT)++Copyright (c) 2016 Daniel Mendler++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Test/QuickCheck/Special.hs view
@@ -0,0 +1,135 @@++{-# LANGUAGE DeriveFunctor #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+module Test.QuickCheck.Special (+  Special(..),+  SpecialValues(..),+) where++import Data.Int+import Data.Word+import Numeric.Natural (Natural)+import Test.QuickCheck+import qualified Data.ByteString as BS+import qualified Data.ByteString.Lazy as BL+import qualified Data.Scientific as Scientific+import qualified Data.Text as TS+import qualified Data.Text.Lazy as TL++-- | Additionally to the standard Arbitrary instances,+-- this generates special values with a small probability.+newtype Special a = Special { getSpecial :: a }+  deriving (Show, Read, Functor, Bounded, Enum, Eq, Ord, Num, Real, Integral)++-- | Provides a list of special values or edge cases+class SpecialValues a where+  -- | Finite list of special values+  specialValues :: [a]++instance SpecialValues Int    where specialValues = specialInt+instance SpecialValues Int8   where specialValues = specialInt+instance SpecialValues Int16  where specialValues = specialInt+instance SpecialValues Int32  where specialValues = specialInt+instance SpecialValues Int64  where specialValues = specialInt+instance SpecialValues Word   where specialValues = specialBoundedEnum+instance SpecialValues Word8  where specialValues = specialBoundedEnum+instance SpecialValues Word16 where specialValues = specialBoundedEnum+instance SpecialValues Word32 where specialValues = specialBoundedEnum+instance SpecialValues Word64 where specialValues = specialBoundedEnum+instance SpecialValues Bool   where specialValues = [True, False]+instance SpecialValues Float  where specialValues = specialIEEE+instance SpecialValues Double where specialValues = specialIEEE++instance SpecialValues Integer where+  specialValues = [ 0, 1, -1+                  , fromIntegral (minBound :: Int64)  - 1+                  , fromIntegral (maxBound :: Int64)  + 1+                  , fromIntegral (maxBound :: Word64) + 1+                  ]++instance SpecialValues Natural where+  specialValues = [ 0, 1, fromIntegral (maxBound :: Word64) + 1 ]++instance SpecialValues Char where+  specialValues = specialBoundedEnum ++ "\0\a\b\f\n\r\t\v\'\"\\aä "++instance SpecialValues TS.Text where+  specialValues = fmap TS.pack specialValues++instance SpecialValues TL.Text where+  specialValues = fmap TL.pack specialValues++instance SpecialValues BS.ByteString where+  specialValues = fmap BS.pack specialValues++instance SpecialValues BL.ByteString where+  specialValues = fmap BL.pack specialValues++instance SpecialValues Scientific.Scientific where+  specialValues = [ fromInteger 0+                  , fromInteger 1, negate $ fromInteger 1+                  , Scientific.scientific 1 (-1000), negate $ Scientific.scientific 1 (-1000)+                  , Scientific.scientific 1 (1000), negate $ Scientific.scientific 1 (1000)+                  ]++instance SpecialValues a => SpecialValues [a] where+  specialValues = [[], specialValues]++instance SpecialValues a => SpecialValues (Maybe a) where+  specialValues = Nothing : fmap Just specialValues++instance (SpecialValues a, SpecialValues b) => SpecialValues (Either a b) where+  specialValues = fmap Left specialValues ++ fmap Right specialValues++instance (SpecialValues a, SpecialValues b) => SpecialValues (a, b) where+  specialValues = zip specialValues specialValues++class RealFloat a => FloatIEEE a where+  nan :: a+  infinity :: a+  epsilon :: a+  minDenormal :: a+  minNormal :: a+  maxFinite :: a++-- echo | gcc -E -dM - | grep _FLT_+instance FloatIEEE Float where+  nan = 0/0+  infinity = 1/0+  epsilon = 1.19209289550781250000e-7+  minDenormal = 1.40129846432481707092e-45+  minNormal = 1.17549435082228750797e-38+  maxFinite = 3.40282346638528859812e+38++-- echo | gcc -E -dM - | grep _DBL_+instance FloatIEEE Double where+  nan = 0/0+  infinity = 1/0+  epsilon = 2.22044604925031308085e-16+  minDenormal = 4.94065645841246544177e-324+  minNormal = 2.22507385850720138309e-308+  maxFinite = 1.79769313486231570815e+308++instance (Arbitrary a, SpecialValues a) => Arbitrary (Special a) where+  shrink = fmap Special . shrink . getSpecial+  arbitrary = fmap Special $ frequency $ list specialValues+    where list s = (10 * length s, arbitrary) : (fmap (\t -> (1, return t)) s)++instance CoArbitrary a => CoArbitrary (Special a) where+  coarbitrary = coarbitrary . getSpecial++specialIEEE :: FloatIEEE a => [a]+specialIEEE = [0, 1, -1+              , nan+              , epsilon, -epsilon+              , infinity, -infinity+              , minDenormal, -minDenormal+              , minNormal, -minNormal+              , maxFinite, -maxFinite+              ]++specialInt :: (Num a, Bounded a) => [a]+specialInt = [0, 1, -1, minBound, maxBound, minBound + 1, maxBound - 1]++specialBoundedEnum :: (Enum a, Bounded a) => [a]+specialBoundedEnum = [minBound, maxBound, succ minBound, pred maxBound]
+ quickcheck-special.cabal view
@@ -0,0 +1,39 @@+-- This file has been generated from package.yaml by hpack version 0.15.0.+--+-- see: https://github.com/sol/hpack++name:           quickcheck-special+version:        0.1.0.0+synopsis:       Edge cases and special values for QuickCheck Arbitrary instances+description:    The standard Arbitrary instances of QuickCheck don't generate special values. This is fixed by this package which provides the newtype Special with an Arbitrary instance. The special values are given by the SpecialValues typeclass.+category:       Testing+homepage:       https://github.com/minad/quickcheck-special#readme+bug-reports:    https://github.com/minad/quickcheck-special/issues+author:         Daniel Mendler <mail@daniel-mendler.de>+maintainer:     Daniel Mendler <mail@daniel-mendler.de>+copyright:      2016 Daniel Mendler+license:        MIT+license-file:   LICENSE+tested-with:    GHC == 7.0.4, GHC == 7.2.2, GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.1+build-type:     Simple+cabal-version:  >= 1.10++source-repository head+  type: git+  location: https://github.com/minad/quickcheck-special++library+  hs-source-dirs:+      .+  ghc-options: -Wall+  build-depends:+      base < 6+    , bytestring >= 0.9 && < 0.11+    , nats >= 1+    , QuickCheck >= 2.1 && < 2.10+    , quickcheck-instances >= 0.3 && < 0.5+    , scientific >= 0.2 && < 0.4+    , text >= 0.7 && < 1.3+  exposed-modules:+      Test.QuickCheck.Special+  default-language: Haskell2010