on master help sign in
Move unsquare to a happier place

--HG-- extra : convert_revision : 6a4ddc91282f75386bb65e41fd04c6b9c9898cf4

commit1fd4770edb71fd4298871af372d88240c1b2545b authorBryan O'Sullivan <bos@serpentine.com> dateSun 29 Aug 2010, 17:00 (16 years ago) parent73b7ae9
2 files changed+8−8
tests/Properties.hs+1−7 tests/QuickCheckUtils.hs+7−1
tests/Properties.hs+1−7
@@ -39,7 +39,7 @@ import Data.Text.Search (indices)
3939import qualified Data.Text.Lazy.Search as S (indices)
4040import qualified SlowFunctions as Slow
4141
42−import QuickCheckUtils (NotEmpty(..), small, genUnicode)
42+import QuickCheckUtils (NotEmpty(..), genUnicode, small, unsquare)
4343import TestUtils (withRedirect, withTempFile)
4444
4545-- Ensure that two potentially bottom values (in the sense of crashing
@@ -158,12 +158,6 @@ eqP f g s w = eql "orig" (f s) (g t) &&
158158 | a =^= b = True
159159 | otherwise = trace (d ++ ": " ++ show a ++ " /= " ++ show b) False
160160
161−-- For tests that have O(n^2) running times or input sizes, resize
162−-- their inputs to the square root of the originals.
163−unsquare :: (Arbitrary a, Show a, Testable b) => (a -> b) -> Property
164−unsquare = forAll . sized $ \n -> resize (smallish n) arbitrary
165− where smallish = round . (sqrt :: Double -> Double) . fromIntegral
166−
167161s_Eq s = (s==) `eq` ((S.streamList s==) . S.streamList)
168162 where _types = s :: String
169163sf_Eq p s =
tests/QuickCheckUtils.hs+7−1
@@ -11,7 +11,7 @@ import Data.String (IsString, fromString)
1111import qualified Data.Text as T
1212import qualified Data.Text.Lazy as TL
1313import System.Random (Random(..), RandomGen)
14−import Test.QuickCheck (Gen, Arbitrary(..), choose, sized, vector, oneof)
14+import Test.QuickCheck hiding ((.&.))
1515import qualified Data.ByteString as B
1616
1717instance Random Int64 where
@@ -98,6 +98,12 @@ genUnicode = fmap fromString string where
9898instance Arbitrary T.Text where
9999 arbitrary = T.pack `fmap` arbitrary
100100
101+-- For tests that have O(n^2) running times or input sizes, resize
102+-- their inputs to the square root of the originals.
103+unsquare :: (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
106+
101107instance Arbitrary TL.Text where
102108 arbitrary = (TL.fromChunks . map notEmpty) `fmap` arbitrary
103109