@@ -49,7 +49,16 @@ import Test.Hspec
4949import Test.Hspec.Laws
5050 ( testLawsMany )
5151import 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+ )
5362import Test.QuickCheck.Classes
5463 ( Laws (.. ) )
5564import Test.QuickCheck.Classes.Monoid.Factorial
@@ -80,17 +89,13 @@ import Test.QuickCheck.Classes.Semigroup.Cancellative
8089 )
8190import 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- ()
9192import 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+
9499spec :: Spec
95100spec = 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+
554563instance 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