on master help sign in
Fix up test performance and reliability.

--HG-- extra : convert_revision : f2538c17e04c880cde55f529333c6d96cc9447a2

commit146e2c2fe1296ec3d63a4e709341e4de6886ea6f authorBryan O'Sullivan <bos@serpentine.com> dateSat 15 Aug 2009, 01:33 (17 years ago) parent65c17af
1 file changed+28−18
tests/Properties.hs+28−18
tests/Properties.hs+28−18
@@ -119,6 +119,12 @@ eqP a b s w = eq "orig" (a s) (b t) &&
119119 eq s a b | a =^= b = True
120120 | otherwise = trace (s ++ ": " ++ show a ++ " /= " ++ show b) False
121121
122+-- For tests that have O(n^2) running times or input sizes, resize
123+-- their inputs to the square root of the originals.
124+unsquare :: (Arbitrary a, Show a, Testable b) => (a -> b) -> Property
125+unsquare = forAll . sized $ \n -> resize (smaller n) arbitrary
126+ where smaller = round . sqrt . fromIntegral
127+
122128prop_S_Eq s = (s==) `eq` ((S.stream s==) . S.stream)
123129prop_T_Eq s = (s==) `eq` ((T.pack s==) . T.pack)
124130prop_TL_Eq s = (s==) `eq` ((TL.pack s==) . TL.pack)
@@ -131,8 +137,8 @@ prop_T_Show = show `eq` (show . T.pack)
131137prop_TL_Show = show `eq` (show . TL.pack)
132138prop_T_mappend s = mappend s`eqP` (unpackS . mappend (T.pack s))
133139prop_TL_mappend s = mappend s`eqP` (unpackS . mappend (TL.pack s))
134−prop_T_mconcat = mconcat `eq` (unpackS . mconcat . L.map T.pack)
135−prop_TL_mconcat = mconcat `eq` (unpackS . mconcat . L.map TL.pack)
140+prop_T_mconcat = unsquare (mconcat `eq` (unpackS . mconcat . L.map T.pack))
141+prop_TL_mconcat = unsquare (mconcat `eq` (unpackS . mconcat . L.map TL.pack))
136142prop_T_IsString = fromString `eqP` (T.unpack . fromString)
137143prop_TL_IsString = fromString `eqP` (TL.unpack . fromString)
138144
@@ -172,12 +178,12 @@ prop_T_length = length `eqP` T.length
172178prop_TL_length = length `eqP` (fromIntegral . TL.length)
173179prop_T_map f = map f `eqP` (unpackS . T.map f)
174180prop_TL_map f = map f `eqP` (unpackS . TL.map f)
175−prop_T_intercalate c = L.intercalate c `eq` (unpackS . T.intercalate (packS c) . map packS)
176−prop_TL_intercalate c = L.intercalate c `eq` (unpackS . TL.intercalate (TL.pack c) . map TL.pack)
181+prop_T_intercalate c = unsquare (L.intercalate c `eq` (unpackS . T.intercalate (packS c) . map packS))
182+prop_TL_intercalate c = unsquare (L.intercalate c `eq` (unpackS . TL.intercalate (TL.pack c) . map TL.pack))
177183prop_T_intersperse c = L.intersperse c `eqP` (unpackS . T.intersperse c)
178184prop_TL_intersperse c = L.intersperse c `eqP` (unpackS . TL.intersperse c)
179−prop_T_transpose = L.transpose `eq` (map unpackS . T.transpose . map packS)
180−prop_TL_transpose = L.transpose `eq` (map unpackS . TL.transpose . map TL.pack)
185+prop_T_transpose = unsquare (L.transpose `eq` (map unpackS . T.transpose . map packS))
186+prop_TL_transpose = unsquare (L.transpose `eq` (map unpackS . TL.transpose . map TL.pack))
181187prop_T_reverse = L.reverse `eqP` (unpackS . T.reverse)
182188prop_TL_reverse = L.reverse `eqP` (unpackS . TL.reverse)
183189prop_T_reverse_short n = L.reverse `eqP` (unpackS . S.reverse . shorten n . S.stream)
@@ -231,10 +237,10 @@ prop_TL_foldr f z = L.foldr f z `eqP` TL.foldr f z
231237prop_T_foldr1 f = L.foldr1 f `eqP` T.foldr1 f
232238prop_TL_foldr1 f = L.foldr1 f `eqP` TL.foldr1 f
233239
234−prop_T_concat = L.concat `eq` (unpackS . T.concat . map packS)
235−prop_TL_concat = L.concat `eq` (unpackS . TL.concat . map TL.pack)
236−prop_T_concatMap f = L.concatMap f `eqP` (unpackS . T.concatMap (packS . f))
237−prop_TL_concatMap f = L.concatMap f `eqP` (unpackS . TL.concatMap (TL.pack . f))
240+prop_T_concat = unsquare (L.concat `eq` (unpackS . T.concat . map packS))
241+prop_TL_concat = unsquare (L.concat `eq` (unpackS . TL.concat . map TL.pack))
242+prop_T_concatMap f = unsquare (L.concatMap f `eqP` (unpackS . T.concatMap (packS . f)))
243+prop_TL_concatMap f = unsquare (L.concatMap f `eqP` (unpackS . TL.concatMap (TL.pack . f)))
238244prop_T_any p = L.any p `eqP` T.any p
239245prop_TL_any p = L.any p `eqP` TL.any p
240246prop_T_all p = L.all p `eqP` T.all p
@@ -362,11 +368,12 @@ prop_T_lines' = lines' `eqP` (map unpackS . T.lines')
362368 eol c = c == '\r' || c == '\n'
363369-}
364370prop_T_words = L.words `eqP` (map unpackS . T.words)
371+
365372prop_TL_words = L.words `eqP` (map unpackS . TL.words)
366−prop_T_unlines = L.unlines `eq` (unpackS . T.unlines . map packS)
367−prop_TL_unlines = L.unlines `eq` (unpackS . TL.unlines . map packS)
368−prop_T_unwords = L.unwords `eq` (unpackS . T.unwords . map packS)
369−prop_TL_unwords = L.unwords `eq` (unpackS . TL.unwords . map packS)
373+prop_T_unlines = unsquare (L.unlines `eq` (unpackS . T.unlines . map packS))
374+prop_TL_unlines = unsquare (L.unlines `eq` (unpackS . TL.unlines . map packS))
375+prop_T_unwords = unsquare (L.unwords `eq` (unpackS . T.unwords . map packS))
376+prop_TL_unwords = unsquare (L.unwords `eq` (unpackS . TL.unwords . map packS))
370377
371378prop_S_isPrefixOf s = L.isPrefixOf s`eqP` (S.isPrefixOf (S.stream $ packS s) . S.stream)
372379prop_T_isPrefixOf s = L.isPrefixOf s`eqP` T.isPrefixOf (packS s)
@@ -385,10 +392,12 @@ prop_TL_find p = L.find p `eqP` TL.find p
385392prop_T_partition p = L.partition p `eqP` (unpack2 . T.partition p)
386393prop_TL_partition p = L.partition p `eqP` (unpack2 . TL.partition p)
387394
388−prop_T_index x s = x < L.length s && x >= 0 ==>
389− (L.!!) s x == T.index (packS s) x
390−prop_TL_index x s = x < L.length s && x >= 0 ==>
391− (L.!!) s x == TL.index (packS s) (fromIntegral x)
395+prop_T_index s = forAll (choose (-l,l*2)) ((s L.!!) `eq` T.index (packS s))
396+ where l = L.length s
397+
398+prop_TL_index s = forAll (choose (-l,l*2)) ((s L.!!) `eq` (TL.index (packS s) . fromIntegral))
399+ where l = L.length s
400+
392401prop_T_findIndex p = L.findIndex p `eqP` T.findIndex p
393402prop_TL_findIndex p = (fmap fromIntegral . L.findIndex p) `eqP` TL.findIndex p
394403prop_T_findIndices p = L.findIndices p `eqP` T.findIndices p
@@ -644,6 +653,7 @@ tests = [
644653 ("prop_TL_partition", mytest prop_TL_partition),
645654
646655 ("prop_T_index", mytest prop_T_index),
656+ ("prop_TL_index", mytest prop_TL_index),
647657 ("prop_T_findIndex", mytest prop_T_findIndex),
648658 ("prop_TL_findIndex", mytest prop_TL_findIndex),
649659 ("prop_T_findIndices", mytest prop_T_findIndices),