1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 07:55:12 +03:00

Simplify the definition of shrink over ArbitraryTerm.

This commit is contained in:
Rob Rix 2016-05-31 20:31:32 -04:00
parent 36168c1698
commit 514c513f13

View File

@ -37,11 +37,11 @@ instance (Eq a, Eq annotation, Arbitrary a, Arbitrary annotation) => Arbitrary (
(1, Keyed . Map.fromList . take maxLength <$> listOf (arbitrary >>= (\x -> (,) x <$> smallerTerm maxLength maxDepth))) ]
smallerTerm maxLength maxDepth = boundedTerm (div maxLength 3) (div maxDepth 3)
shrink term@(ArbitraryTerm (annotation :< syntax)) = (subterms term ++) $ filter (/= term) $
ArbitraryTerm <$> ((:<) <$> shrink annotation <*> case syntax of
(ArbitraryTerm .) . (:<) <$> shrink annotation <*> case syntax of
Leaf a -> Leaf <$> shrink a
Indexed i -> Indexed <$> (List.subsequences i >>= recursivelyShrink)
Fixed f -> Fixed <$> (List.subsequences f >>= recursivelyShrink)
Keyed k -> Keyed . Map.fromList <$> (List.subsequences (Map.toList k) >>= recursivelyShrink))
Keyed k -> Keyed . Map.fromList <$> (List.subsequences (Map.toList k) >>= recursivelyShrink)
data CategorySet = A | B | C | D deriving (Eq, Show)