Skip to content

Commit 0086aa7

Browse files
author
Ross Paterson
committed
Fix Arbitrary instance for FingerTree
The previous version never generated deep trees containing Empty. Also tweaked the size handling so that the tree size is closer to the specified size (though it can still run over a bit).
1 parent 314f798 commit 0086aa7

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)