@@ -28,9 +28,7 @@ import Foreign (minusPtr)
2828import Data.Char (chr )
2929import Data.Bits ((.|.) , shiftL )
3030import Data.Foldable
31- #if !MIN_VERSION_base(4,11,0)
32- import Data.Semigroup
33- #endif
31+ import Data.Semigroup (Semigroup (.. ))
3432import Data.Word
3533
3634import qualified Data.ByteString as S
@@ -55,8 +53,11 @@ import System.Posix.Internals (c_unlink)
5553import Test.Tasty (TestTree , TestName , testGroup )
5654import Test.Tasty.QuickCheck
5755 ( Arbitrary (.. ), oneof , choose , listOf , elements
58- , counterexample , ioProperty , UnicodeString (.. ), Property , testProperty
59- , (===) , (.&&.) , conjoin )
56+ , counterexample , ioProperty , Property , testProperty
57+ , (===) , (.&&.) , conjoin
58+ , UnicodeString (.. ), NonNegative (.. )
59+ )
60+ import QuickCheckUtils
6061
6162
6263tests :: [TestTree ]
@@ -67,6 +68,7 @@ tests =
6768 , testPut
6869 , testRunBuilder
6970 , testWriteFile
71+ , testStimes
7072 ] ++
7173 testsEncodingToBuilder ++
7274 testsBinary ++
@@ -199,6 +201,11 @@ testWriteFile =
199201 unless success (error msg)
200202 return success
201203
204+ testStimes :: TestTree
205+ testStimes = testProperty " stimes" $
206+ \ (Sqrt (NonNegative n)) (Sqrt x) ->
207+ stimes (n :: Int ) x === toLazyByteString (stimes n (lazyByteString x))
208+
202209removeFile :: String -> IO ()
203210removeFile fn = void $ withCString fn c_unlink
204211
@@ -319,22 +326,6 @@ recipeComponents (Recipe how firstSize otherSize cont as) =
319326-- 'Arbitary' instances
320327-----------------------
321328
322- instance Arbitrary L. ByteString where
323- arbitrary = L. fromChunks <$> listOf arbitrary
324- shrink lbs
325- | L. null lbs = []
326- | otherwise = pure $ L. take (L. length lbs `div` 2 ) lbs
327-
328- instance Arbitrary S. ByteString where
329- arbitrary =
330- trim S. drop =<< trim S. take =<< S. pack <$> listOf arbitrary
331- where
332- trim f bs = oneof [pure bs, f <$> choose (0 , S. length bs) <*> pure bs]
333-
334- shrink bs
335- | S. null bs = []
336- | otherwise = pure $ S. take (S. length bs `div` 2 ) bs
337-
338329instance Arbitrary Mode where
339330 arbitrary = oneof
340331 [Threshold <$> arbitrary, pure Smart , pure Insert , pure Copy , pure Hex ]
0 commit comments