git.iko.soy/typeable/generic-arbitrary
on master help sign in
Merge remote-tracking branch 'origin/klntsky/fix-resize-bug' into fix-instances
commit7c71d91ede9b71859430cbb535cef3759eafdb97 authorAleksey Uymanov <s9gf4ult@gmail.com> dateThu 29 Jul 2021, 15:57 (5 years ago) parentc58b7fcc13d119
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))