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:
parent
6a7ec24640
commit
5b5add0c2d
@ -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)
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user