on master help sign in
Make arbitrary lazy texts smaller

--HG-- extra : convert_revision : 4fa71afa3bf17408ddca5dd95a2b1358cb67202e

commit0eb5042b8506146540baebfc6bb96c31a1877f65 authorBryan O'Sullivan <bos@serpentine.com> dateSun 29 Aug 2010, 18:07 (16 years ago) parent3dc8449
1 file changed+9−6
tests/QuickCheckUtils.hs+9−6
tests/QuickCheckUtils.hs+9−6
@@ -95,17 +95,20 @@ genUnicode = fmap fromString string where
9595
9696 char = chr `fmap` excluding reserved (oneof planes)
9797
98−instance Arbitrary T.Text where
99− arbitrary = T.pack `fmap` arbitrary
100−
10198-- For tests that have O(n^2) running times or input sizes, resize
10299-- their inputs to the square root of the originals.
103100unsquare :: (Arbitrary a, Show a, Testable b) => (a -> b) -> Property
104−unsquare = forAll . sized $ \n -> resize (smallish n) arbitrary
105− where smallish = round . (sqrt :: Double -> Double) . fromIntegral
101+unsquare = forAll smallArbitrary
102+
103+smallArbitrary :: (Arbitrary a, Show a) => Gen a
104+smallArbitrary = sized $ \n -> resize (smallish n) arbitrary
105+ where smallish = round . (sqrt :: Double -> Double) . fromIntegral . abs
106+
107+instance Arbitrary T.Text where
108+ arbitrary = T.pack `fmap` arbitrary
106109
107110instance Arbitrary TL.Text where
108− arbitrary = (TL.fromChunks . map notEmpty) `fmap` arbitrary
111+ arbitrary = (TL.fromChunks . map notEmpty) `fmap` smallArbitrary
109112
110113newtype NotEmpty a = NotEmpty { notEmpty :: a }
111114 deriving (Eq, Ord)