mirror of
https://github.com/github/semantic.git
synced 2024-12-26 00:12:29 +03:00
Generate arbitrary terms using frequency & sized bounds.
This commit is contained in:
parent
046c3d1813
commit
2764c34b8d
@ -32,7 +32,12 @@ instance (Eq a, Eq f, Arbitrary a, Arbitrary f) => Arbitrary (Syntax a f) where
|
|||||||
shrinkSyntax (Keyed k) = Keyed . Map.fromList <$> (List.subsequences (Map.toList k) >>= shrink)
|
shrinkSyntax (Keyed k) = Keyed . Map.fromList <$> (List.subsequences (Map.toList k) >>= shrink)
|
||||||
|
|
||||||
instance (Eq a, Eq annotation, Arbitrary a, Arbitrary annotation) => Arbitrary (ArbitraryTerm a annotation) where
|
instance (Eq a, Eq annotation, Arbitrary a, Arbitrary annotation) => Arbitrary (ArbitraryTerm a annotation) where
|
||||||
arbitrary = arbitraryBounded 4
|
arbitrary = sized boundedTerm
|
||||||
|
where boundedTerm n = ArbitraryTerm <$> ((,) <$> arbitrary <*> boundedSyntax n)
|
||||||
|
boundedSyntax 0 = liftM Leaf arbitrary
|
||||||
|
boundedSyntax n = frequency
|
||||||
|
[ (1, liftM Leaf arbitrary),
|
||||||
|
(4, liftM Indexed $ listOf $ boundedTerm $ n - 1) ]
|
||||||
shrink term@(ArbitraryTerm (annotation, syntax)) = (++) (subterms term) $ filter (/= term) $ ArbitraryTerm <$> ((,) <$> shrink annotation <*> shrinkSyntax syntax)
|
shrink term@(ArbitraryTerm (annotation, syntax)) = (++) (subterms term) $ filter (/= term) $ ArbitraryTerm <$> ((,) <$> shrink annotation <*> shrinkSyntax syntax)
|
||||||
where shrinkSyntax (Leaf a) = Leaf <$> shrink a
|
where shrinkSyntax (Leaf a) = Leaf <$> shrink a
|
||||||
shrinkSyntax (Indexed i) = Indexed <$> (List.subsequences i >>= recursivelyShrink)
|
shrinkSyntax (Indexed i) = Indexed <$> (List.subsequences i >>= recursivelyShrink)
|
||||||
|
Loading…
Reference in New Issue
Block a user