Skip to content

Commit 54c3603

Browse files
committed
Merge pull request #108 from RossPaterson/master
Fix Arbitrary instance for FingerTree
2 parents 314f798 + 0086aa7 commit 54c3603

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tests/seq-properties.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,15 @@ instance (Arbitrary a, Sized a) => Arbitrary (FingerTree a) where
112112
arb :: (Arbitrary a, Sized a) => Int -> Gen (FingerTree a)
113113
arb 0 = return Empty
114114
arb 1 = Single <$> arbitrary
115-
arb n = deep <$> arbitrary <*> arb (n `div` 2) <*> arbitrary
115+
arb n = do
116+
pr <- arbitrary
117+
sf <- arbitrary
118+
let n_pr = Prelude.length (toList pr)
119+
let n_sf = Prelude.length (toList sf)
120+
-- adding n `div` 7 ensures that n_m >= 0, and makes more Singles
121+
let n_m = max (n `div` 7) ((n - n_pr - n_sf) `div` 3)
122+
m <- arb n_m
123+
return $ deep pr m sf
116124

117125
shrink (Deep _ (One a) Empty (One b)) = [Single a, Single b]
118126
shrink (Deep _ pr m sf) =

0 commit comments

Comments
 (0)