1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 08:25:19 +03:00

Rename m to maxLength.

This commit is contained in:
Rob Rix 2015-12-14 15:17:26 -05:00
parent 5c90ecde8e
commit 686325bf4c

View File

@ -28,14 +28,14 @@ unTerm arbitraryTerm = unfold unpack arbitraryTerm
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 = sized (\ x -> boundedTerm x x) -- first indicates the cube of the max length of lists, second indicates the cube of the max depth of the tree arbitrary = sized (\ x -> boundedTerm x x) -- first indicates the cube of the max length of lists, second indicates the cube of the max depth of the tree
where boundedTerm m n = ArbitraryTerm <$> ((,) <$> arbitrary <*> boundedSyntax m n) where boundedTerm maxLength n = ArbitraryTerm <$> ((,) <$> arbitrary <*> boundedSyntax maxLength n)
boundedSyntax _ n | n <= 0 = liftM Leaf arbitrary boundedSyntax _ n | n <= 0 = liftM Leaf arbitrary
boundedSyntax m n = frequency boundedSyntax maxLength n = frequency
[ (12, liftM Leaf arbitrary), [ (12, liftM Leaf arbitrary),
(1, liftM Indexed $ take m <$> listOf (smallerTerm m n)), (1, liftM Indexed $ take maxLength <$> listOf (smallerTerm maxLength n)),
(1, liftM Fixed $ take m <$> listOf (smallerTerm m n)), (1, liftM Fixed $ take maxLength <$> listOf (smallerTerm maxLength n)),
(1, liftM (Keyed . Map.fromList) $ take n <$> listOf (arbitrary >>= (\x -> ((,) x) <$> smallerTerm m n))) ] (1, liftM (Keyed . Map.fromList) $ take n <$> listOf (arbitrary >>= (\x -> ((,) x) <$> smallerTerm maxLength n))) ]
smallerTerm m n = boundedTerm (div m 3) (div n 3) smallerTerm maxLength n = boundedTerm (div maxLength 3) (div n 3)
shrink term@(ArbitraryTerm (annotation, syntax)) = (++) (subterms term) $ filter (/= term) $ 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 Leaf a -> Leaf <$> shrink a