git.iko.soy/typeable/generic-arbitrary
on master help sign in
Put `scale` call to the right place.
commitc13d119d8ad0d43860ecdb93b357b0239e366a6c authorVladimir Kalnitsky <klntsky@typeable.io> dateWed 28 Jul 2021, 17:23 (5 years ago) parent0547fe7
1 file changed+6−3
src/Test/QuickCheck/Arbitrary/Generic.hs+6−3
src/Test/QuickCheck/Arbitrary/Generic.hs+6−3
@@ -65,7 +65,10 @@ instance GArbitrary G.U1 where
6565 gArbitrary = pure G.U1
6666
6767instance 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
6972
7073instance GArbitrary f => GArbitrary (G.M1 i c f) where
7174 gArbitrary = G.M1 <$> gArbitrary
@@ -82,8 +85,8 @@ type family SumLen a :: Nat where
8285instance (GArbitrary a, GArbitrary b, KnownNat (SumLen a), KnownNat (SumLen b)
8386 ) => GArbitrary (a G.:+: b) where
8487 gArbitrary = frequency
85− [ (lfreq, G.L1 <$> QC.scale pred gArbitrary)
86− , (rfreq, G.R1 <$> QC.scale pred gArbitrary) ]
88+ [ (lfreq, G.L1 <$> gArbitrary)
89+ , (rfreq, G.R1 <$> gArbitrary) ]
8790 where
8891 lfreq = fromIntegral $ natVal (Proxy :: Proxy (SumLen a))
8992 rfreq = fromIntegral $ natVal (Proxy :: Proxy (SumLen b))