Skip to content

Commit 646a9b6

Browse files
Remove dependency on quickcheck-instances. (#96)
2 parents ebd8e75 + 752061d commit 646a9b6

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

quickcheck-monoid-subclasses.cabal

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ common dependency-QuickCheck
3636
build-depends:QuickCheck >= 2.14.2 && < 2.16
3737
common dependency-quickcheck-classes
3838
build-depends:quickcheck-classes >= 0.6.5.0 && < 0.7
39-
common dependency-quickcheck-instances
40-
build-depends:quickcheck-instances >= 0.3.28 && < 0.4
4139
common dependency-semigroupoids
4240
build-depends:semigroupoids >= 5.3.7 && < 6.1
4341
common dependency-text
@@ -109,7 +107,6 @@ library prelude
109107
, dependency-monoid-subclasses
110108
, dependency-QuickCheck
111109
, dependency-quickcheck-classes
112-
, dependency-quickcheck-instances
113110
, extensions
114111
build-depends:
115112
, internal
@@ -131,7 +128,6 @@ test-suite test
131128
, dependency-monoid-subclasses
132129
, dependency-QuickCheck
133130
, dependency-quickcheck-classes
134-
, dependency-quickcheck-instances
135131
, dependency-text
136132
, dependency-vector
137133
, extensions

src/prelude/Internal/Prelude.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,3 @@ import Internal.Semigroup.Eq
2626
import Internal.Semigroup.Tuple
2727
import Numeric.Natural
2828
import Test.QuickCheck
29-
import Test.QuickCheck.Instances.Natural
30-
()

src/test/ClassSpec.hs

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,16 @@ import Test.Hspec
4949
import Test.Hspec.Laws
5050
( testLawsMany )
5151
import Test.QuickCheck
52-
( Arbitrary (..), Confidence, Property, scale, shrinkMap )
52+
( Arbitrary (..)
53+
, Confidence
54+
, Property
55+
, elements
56+
, frequency
57+
, listOf
58+
, scale
59+
, shrinkIntegral
60+
, shrinkMap
61+
)
5362
import Test.QuickCheck.Classes
5463
( Laws (..) )
5564
import Test.QuickCheck.Classes.Monoid.Factorial
@@ -80,17 +89,13 @@ import Test.QuickCheck.Classes.Semigroup.Cancellative
8089
)
8190
import Test.QuickCheck.Classes.Semigroup.Factorial
8291
( factorialLaws, stableFactorialLaws )
83-
import Test.QuickCheck.Instances.ByteString
84-
()
85-
import Test.QuickCheck.Instances.Natural
86-
()
87-
import Test.QuickCheck.Instances.Text
88-
()
89-
import Test.QuickCheck.Instances.Vector
90-
()
9192
import Test.QuickCheck.Property
9293
( Result (..), mapTotalResult )
9394

95+
import qualified Data.ByteString.Lazy as ByteString
96+
import qualified Data.Text as Text
97+
import qualified Data.Vector as Vector
98+
9499
spec :: Spec
95100
spec = do
96101
testLawsMany @() $ fmap disableCoverageCheck <$>
@@ -551,10 +556,44 @@ newtype Small a = Small {getSmall :: a}
551556
, SumCancellative
552557
)
553558

559+
--------------------------------------------------------------------------------
560+
-- Arbitrary instances
561+
--------------------------------------------------------------------------------
562+
554563
instance Arbitrary a => Arbitrary (Small a) where
555564
arbitrary = Small <$> scale (`div` 2) arbitrary
556565
shrink = shrinkMap Small getSmall
557566

567+
instance Arbitrary ByteString where
568+
arbitrary = ByteString.pack <$> listOf genByte
569+
where
570+
genByte = frequency
571+
[ (64, pure 0)
572+
, (16, pure 1)
573+
, ( 4, pure 2)
574+
, ( 1, pure 3)
575+
]
576+
shrink = shrinkMap ByteString.pack ByteString.unpack
577+
578+
instance Arbitrary Text where
579+
arbitrary = Text.pack <$> listOf genChar
580+
where
581+
genChar = frequency
582+
[ (64, pure 'a')
583+
, (16, pure 'b')
584+
, ( 4, pure 'c')
585+
, ( 1, pure 'd')
586+
]
587+
shrink = shrinkMap Text.pack Text.unpack
588+
589+
instance Arbitrary Natural where
590+
arbitrary = elements [0 .. 3]
591+
shrink = shrinkIntegral
592+
593+
instance Arbitrary a => Arbitrary (Vector a) where
594+
arbitrary = Vector.fromList <$> arbitrary
595+
shrink = shrinkMap Vector.fromList Vector.toList
596+
558597
--------------------------------------------------------------------------------
559598
-- Coverage checks
560599
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)