on master help sign in
Make arbitrary lazy texts smaller
0eb5042Bryan O'Sullivan
tests/QuickCheckUtils.hs+9−6
@@ -95,17 +95,20 @@ genUnicode = fmap fromString string where
95
95
96 char = chr `fmap` excluding reserved (oneof planes)
96 char = chr `fmap` excluding reserved (oneof planes)
97
97
98−instance Arbitrary T.Text where
99− arbitrary = T.pack `fmap` arbitrary
100−
101-- For tests that have O(n^2) running times or input sizes, resize
98-- For tests that have O(n^2) running times or input sizes, resize
102-- their inputs to the square root of the originals.
99-- their inputs to the square root of the originals.
103unsquare :: (Arbitrary a, Show a, Testable b) => (a -> b) -> Property
100unsquare :: (Arbitrary a, Show a, Testable b) => (a -> b) -> Property
101+unsquare = forAll smallArbitrary
102+
103+smallArbitrary :: (Arbitrary a, Show a) => Gen a
104−unsquare = forAll . sized $ \n -> resize (smallish n) arbitrary
104+smallArbitrary = sized $ \n -> resize (smallish n) arbitrary
105− where smallish = round . (sqrt :: Double -> Double) . fromIntegral
105+ where smallish = round . (sqrt :: Double -> Double) . fromIntegral . abs
106+
107+instance Arbitrary T.Text where
108+ arbitrary = T.pack `fmap` arbitrary
106
109
107instance Arbitrary TL.Text where
110instance Arbitrary TL.Text where
108− arbitrary = (TL.fromChunks . map notEmpty) `fmap` arbitrary
111+ arbitrary = (TL.fromChunks . map notEmpty) `fmap` smallArbitrary
109
112
110newtype NotEmpty a = NotEmpty { notEmpty :: a }
113newtype NotEmpty a = NotEmpty { notEmpty :: a }
111 deriving (Eq, Ord)
114 deriving (Eq, Ord)