From 32d460bce77122fbfc27e10dffde0e6d967e2a25 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 14 Dec 2015 15:18:16 -0500 Subject: [PATCH] Rename `n` to `maxDepth`. --- test/Spec.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/Spec.hs b/test/Spec.hs index ec1468be6..41792360d 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -28,14 +28,14 @@ unTerm arbitraryTerm = unfold unpack arbitraryTerm 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 - where boundedTerm maxLength n = ArbitraryTerm <$> ((,) <$> arbitrary <*> boundedSyntax maxLength n) - boundedSyntax _ n | n <= 0 = liftM Leaf arbitrary - boundedSyntax maxLength n = frequency + where boundedTerm maxLength maxDepth = ArbitraryTerm <$> ((,) <$> arbitrary <*> boundedSyntax maxLength maxDepth) + boundedSyntax _ maxDepth | maxDepth <= 0 = liftM Leaf arbitrary + boundedSyntax maxLength maxDepth = frequency [ (12, liftM Leaf arbitrary), - (1, liftM Indexed $ take maxLength <$> listOf (smallerTerm maxLength n)), - (1, liftM Fixed $ take maxLength <$> listOf (smallerTerm maxLength n)), - (1, liftM (Keyed . Map.fromList) $ take n <$> listOf (arbitrary >>= (\x -> ((,) x) <$> smallerTerm maxLength n))) ] - smallerTerm maxLength n = boundedTerm (div maxLength 3) (div n 3) + (1, liftM Indexed $ take maxLength <$> listOf (smallerTerm maxLength maxDepth)), + (1, liftM Fixed $ take maxLength <$> listOf (smallerTerm maxLength maxDepth)), + (1, liftM (Keyed . Map.fromList) $ take maxDepth <$> 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 Leaf a -> Leaf <$> shrink a