1
1
mirror of https://github.com/github/semantic.git synced 2024-12-30 02:14:20 +03:00

Only generate leaves when the size is <= 1.

This commit is contained in:
Rob Rix 2016-06-01 12:07:16 -04:00
parent 6a7ec24640
commit 5b5add0c2d

View File

@ -17,9 +17,10 @@ toTerm = unfold unArbitraryTerm
termOfSize :: (Arbitrary leaf, Arbitrary annotation) => Int -> Gen (ArbitraryTerm leaf annotation)
termOfSize n = (ArbitraryTerm .) . (:<) <$> arbitrary <*> syntaxOfSize n
where syntaxOfSize n = oneof
[ Leaf <$> arbitrary
, Indexed <$> childrenOfSize (pred n)
where syntaxOfSize n | n <= 1 = oneof $ (Leaf <$> arbitrary) : branchGeneratorsOfSize n
| otherwise = oneof $ branchGeneratorsOfSize n
branchGeneratorsOfSize n =
[ Indexed <$> childrenOfSize (pred n)
, Fixed <$> childrenOfSize (pred n)
, (Keyed .) . (Map.fromList .) . zip <$> infiniteListOf arbitrary <*> childrenOfSize (pred n)
]