1
1
mirror of https://github.com/github/semantic.git synced 2024-12-20 21:31:48 +03:00

Generate arbitrarily-sized terms.

This commit is contained in:
Rob Rix 2016-06-01 12:17:42 -04:00
parent 5b5add0c2d
commit 1e049c7dcb

View File

@ -35,7 +35,9 @@ termOfSize n = (ArbitraryTerm .) . (:<) <$> arbitrary <*> syntaxOfSize n
-- Instances
instance (Eq leaf, Eq annotation, Arbitrary leaf, Arbitrary annotation) => Arbitrary (ArbitraryTerm leaf annotation) where
arbitrary = sized termOfSize
arbitrary = sized $ \ n -> do
m <- choose (0, n)
termOfSize m
shrink term@(ArbitraryTerm (annotation :< syntax)) = (subterms term ++) $ filter (/= term) $
(ArbitraryTerm .) . (:<) <$> shrink annotation <*> case syntax of