mirror of
https://github.com/github/semantic.git
synced 2024-12-01 09:15:01 +03:00
Don’t try to create replacements of size 1.
This commit is contained in:
parent
a18b5bb4f0
commit
81fc2ea122
@ -20,9 +20,11 @@ toDiff :: ArbitraryDiff leaf annotation -> Diff leaf annotation
|
|||||||
toDiff = fmap (fmap toTerm) . unfold unArbitraryDiff
|
toDiff = fmap (fmap toTerm) . unfold unArbitraryDiff
|
||||||
|
|
||||||
diffOfSize :: (Arbitrary leaf, Arbitrary annotation) => Int -> Gen (ArbitraryDiff leaf annotation)
|
diffOfSize :: (Arbitrary leaf, Arbitrary annotation) => Int -> Gen (ArbitraryDiff leaf annotation)
|
||||||
diffOfSize n = oneof
|
diffOfSize n
|
||||||
[ (ArbitraryDiff .) . (Free .) . (:<) <$> arbitrary <*> syntaxOfSize n
|
| n <= 0 = (ArbitraryDiff .) . (Free .) . (:<) <$> arbitrary <*> syntaxOfSize n
|
||||||
, ArbitraryDiff . Pure <$> patchOfSize n ]
|
| otherwise = oneof
|
||||||
|
[ (ArbitraryDiff .) . (Free .) . (:<) <$> arbitrary <*> syntaxOfSize n
|
||||||
|
, ArbitraryDiff . Pure <$> patchOfSize n ]
|
||||||
where syntaxOfSize n | n <= 1 = oneof $ (Leaf <$> arbitrary) : branchGeneratorsOfSize n
|
where syntaxOfSize n | n <= 1 = oneof $ (Leaf <$> arbitrary) : branchGeneratorsOfSize n
|
||||||
| otherwise = oneof $ branchGeneratorsOfSize n
|
| otherwise = oneof $ branchGeneratorsOfSize n
|
||||||
branchGeneratorsOfSize n =
|
branchGeneratorsOfSize n =
|
||||||
@ -36,6 +38,8 @@ diffOfSize n = oneof
|
|||||||
first <- diffOfSize m
|
first <- diffOfSize m
|
||||||
rest <- childrenOfSize (n - m)
|
rest <- childrenOfSize (n - m)
|
||||||
pure $! first : rest
|
pure $! first : rest
|
||||||
|
patchOfSize 1 = oneof [ Insert <$> termOfSize 1
|
||||||
|
, Delete <$> termOfSize 1 ]
|
||||||
patchOfSize n = do
|
patchOfSize n = do
|
||||||
m <- choose (1, n - 1)
|
m <- choose (1, n - 1)
|
||||||
left <- termOfSize m
|
left <- termOfSize m
|
||||||
|
Loading…
Reference in New Issue
Block a user