on master help sign in
Move unsquare to a happier place
1fd4770Bryan O'Sullivan
tests/Properties.hs+1−7
@@ -39,7 +39,7 @@ import Data.Text.Search (indices)
39import qualified Data.Text.Lazy.Search as S (indices)
39import qualified Data.Text.Lazy.Search as S (indices)
40import qualified SlowFunctions as Slow
40import qualified SlowFunctions as Slow
41
41
42−import QuickCheckUtils (NotEmpty(..), small, genUnicode)
42+import QuickCheckUtils (NotEmpty(..), genUnicode, small, unsquare)
43import TestUtils (withRedirect, withTempFile)
43import TestUtils (withRedirect, withTempFile)
44
44
45-- Ensure that two potentially bottom values (in the sense of crashing
45-- 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) &&
158 | a =^= b = True
158 | a =^= b = True
159 | otherwise = trace (d ++ ": " ++ show a ++ " /= " ++ show b) False
159 | otherwise = trace (d ++ ": " ++ show a ++ " /= " ++ show b) False
160
160
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−
167s_Eq s = (s==) `eq` ((S.streamList s==) . S.streamList)
161s_Eq s = (s==) `eq` ((S.streamList s==) . S.streamList)
168 where _types = s :: String
162 where _types = s :: String
169sf_Eq p s =
163sf_Eq p s =
tests/QuickCheckUtils.hs+7−1
@@ -11,7 +11,7 @@ import Data.String (IsString, fromString)
11import qualified Data.Text as T
11import qualified Data.Text as T
12import qualified Data.Text.Lazy as TL
12import qualified Data.Text.Lazy as TL
13import System.Random (Random(..), RandomGen)
13import System.Random (Random(..), RandomGen)
14−import Test.QuickCheck (Gen, Arbitrary(..), choose, sized, vector, oneof)
14+import Test.QuickCheck hiding ((.&.))
15import qualified Data.ByteString as B
15import qualified Data.ByteString as B
16
16
17instance Random Int64 where
17instance Random Int64 where
@@ -98,6 +98,12 @@ genUnicode = fmap fromString string where
98instance Arbitrary T.Text where
98instance Arbitrary T.Text where
99 arbitrary = T.pack `fmap` arbitrary
99 arbitrary = T.pack `fmap` arbitrary
100
100
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+
101instance Arbitrary TL.Text where
107instance Arbitrary TL.Text where
102 arbitrary = (TL.fromChunks . map notEmpty) `fmap` arbitrary
108 arbitrary = (TL.fromChunks . map notEmpty) `fmap` arbitrary
103
109