git.iko.soy/typeable/generic-arbitrary
on master help sign in
Put `scale` call to the right place.
c13d119Vladimir Kalnitsky
src/Test/QuickCheck/Arbitrary/Generic.hs+6−3
@@ -65,7 +65,10 @@ instance GArbitrary G.U1 where
65 gArbitrary = pure G.U1
65 gArbitrary = pure G.U1
66
66
67instance Arbitrary c => GArbitrary (G.K1 i c) where
67instance Arbitrary c => GArbitrary (G.K1 i c) where
68− gArbitrary = G.K1 <$> arbitrary
68+ gArbitrary = G.K1 <$> scale predNat arbitrary
69+ where
70+ predNat 0 = 0
71+ predNat n = pred n
69
72
70instance GArbitrary f => GArbitrary (G.M1 i c f) where
73instance GArbitrary f => GArbitrary (G.M1 i c f) where
71 gArbitrary = G.M1 <$> gArbitrary
74 gArbitrary = G.M1 <$> gArbitrary
@@ -82,8 +85,8 @@ type family SumLen a :: Nat where
82instance (GArbitrary a, GArbitrary b, KnownNat (SumLen a), KnownNat (SumLen b)
85instance (GArbitrary a, GArbitrary b, KnownNat (SumLen a), KnownNat (SumLen b)
83 ) => GArbitrary (a G.:+: b) where
86 ) => GArbitrary (a G.:+: b) where
84 gArbitrary = frequency
87 gArbitrary = frequency
85− [ (lfreq, G.L1 <$> QC.scale pred gArbitrary)
88+ [ (lfreq, G.L1 <$> gArbitrary)
86− , (rfreq, G.R1 <$> QC.scale pred gArbitrary) ]
89+ , (rfreq, G.R1 <$> gArbitrary) ]
87 where
90 where
88 lfreq = fromIntegral $ natVal (Proxy :: Proxy (SumLen a))
91 lfreq = fromIntegral $ natVal (Proxy :: Proxy (SumLen a))
89 rfreq = fromIntegral $ natVal (Proxy :: Proxy (SumLen b))
92 rfreq = fromIntegral $ natVal (Proxy :: Proxy (SumLen b))