packages feed

quickcheck-enum-instances (empty) → 0.1.0.0

raw patch · 5 files changed

+128/−0 lines, 5 filesdep +QuickCheckdep +basedep +enum-typessetup-changed

Dependencies added: QuickCheck, base, enum-types

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Andrew Martin (c) 2018++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Andrew Martin nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,4 @@+# quickcheck-enum++This library provides several enumeration types that are intended+to be used in `QuickCheck` properties.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ quickcheck-enum-instances.cabal view
@@ -0,0 +1,32 @@+cabal-version: 2.0+name: quickcheck-enum-instances+version: 0.1.0.0+description:+  Instances of the `Arbitrary` typeclass for all of the types+  in `enum-types`. These are orphan instances, so this should+  only be used in test suites.+homepage: https://github.com/andrewthad/quickcheck-enum-instances+bug-reports: https://github.com/andrewthad/quickcheck-enum-instances/issues+author: Andrew Martin+maintainer: andrew.thaddeus@gmail.com+copyright: 2018 Andrew Martin+license: BSD3+license-file: LICENSE+build-type: Simple+extra-source-files: README.md+category: Testing+synopsis: arbitrary instances for small enum types++source-repository head+  type: git+  location: https://github.com/andrewthad/quickcheck-enum-instances++library+  exposed-modules: Test.QuickCheck.Instances.Enum+  hs-source-dirs: src+  build-depends:+      base >= 4.9.1.0 && < 5+    , enum-types >= 0.1+    , QuickCheck >= 2.9+  default-language: Haskell2010+
+ src/Test/QuickCheck/Instances/Enum.hs view
@@ -0,0 +1,60 @@+{-# language TypeApplications #-}++module Test.QuickCheck.Instances.Enum () where++import Data.Enum.Types+import Data.Coerce (coerce)+import Test.QuickCheck (Arbitrary(..), arbitraryBoundedEnum)++instance Arbitrary A where+  arbitrary = coerce (arbitrary @(Enumeration A))+  shrink = coerce (shrink @(Enumeration A))++instance Arbitrary B where+  arbitrary = coerce (arbitrary @(Enumeration B))+  shrink = coerce (shrink @(Enumeration B))++instance Arbitrary C where+  arbitrary = coerce (arbitrary @(Enumeration C))+  shrink = coerce (shrink @(Enumeration C))++instance Arbitrary D where+  arbitrary = coerce (arbitrary @(Enumeration D))+  shrink = coerce (shrink @(Enumeration D))++instance Arbitrary E where+  arbitrary = coerce (arbitrary @(Enumeration E))+  shrink = coerce (shrink @(Enumeration E))++instance Arbitrary F where+  arbitrary = coerce (arbitrary @(Enumeration F))+  shrink = coerce (shrink @(Enumeration F))++instance Arbitrary G where+  arbitrary = coerce (arbitrary @(Enumeration G))+  shrink = coerce (shrink @(Enumeration G))++instance Arbitrary H where+  arbitrary = coerce (arbitrary @(Enumeration H))+  shrink = coerce (shrink @(Enumeration H))++instance Arbitrary I where+  arbitrary = coerce (arbitrary @(Enumeration I))+  shrink = coerce (shrink @(Enumeration I))++instance Arbitrary J where+  arbitrary = coerce (arbitrary @(Enumeration J))+  shrink = coerce (shrink @(Enumeration J))++instance Arbitrary K where+  arbitrary = coerce (arbitrary @(Enumeration K))+  shrink = coerce (shrink @(Enumeration K))++newtype Enumeration a = Enumeration a++instance (Bounded a, Enum a, Eq a) => Arbitrary (Enumeration a) where+  arbitrary = fmap Enumeration arbitraryBoundedEnum+  shrink (Enumeration x) = if x == minBound+    then []+    else [Enumeration (pred x)]+