smallcheck-series 0.4 → 0.5
raw patch · 4 files changed
+90/−19 lines, 4 filesdep ~bytestringdep ~smallcheck
Dependency ranges changed: bytestring, smallcheck
Files
- CHANGELOG.md +9/−0
- Test/SmallCheck/Series/Instances.hs +73/−14
- Test/SmallCheck/Series/Utils.hs +5/−2
- smallcheck-series.cabal +3/−3
CHANGELOG.md view
@@ -4,6 +4,14 @@ CHANGELOG](http://keepachangelog.com/). This project adheres to [Semantic Versioning](http://semver.org/). +## [0.5] - 2015-08-31+### Changed+- `Text` and `ByteString` Serial instances are now exhaustive.++### Added+- `Serial` and `CoSerial` instances for `Word`, `Word8`, `Int16`.+- `Serial` and `CoSerial` instances for `Int8`, `Int16`.+ ## [0.4] - 2015-08-06 ### Added - Support for stack.@@ -30,6 +38,7 @@ - Initial set of utilities for creating `ByteString` and `Text` `Series`. - `Serial` `ByteString` and `Text` instances. +[0.5]: https://github.com/jdnavarro/smallcheck-series/compare/v0.4...v0.5 [0.4]: https://github.com/jdnavarro/smallcheck-series/compare/v0.3...v0.4 [0.3]: https://github.com/jdnavarro/smallcheck-series/compare/v0.2...v0.3 [0.2]: https://github.com/jdnavarro/smallcheck-series/compare/v0.1...v0.2
Test/SmallCheck/Series/Instances.hs view
@@ -5,24 +5,38 @@ {-| 'Serial' instances are provided for the following types: +* 'Data.Word'+* 'Data.Word8'+* 'Data.Word16'+* 'Data.Word32'+* 'Data.Word64'+* 'Data.Int8'+* 'Data.Int16'+* 'Data.Int32'+* 'Data.Int64' * 'Data.ByteString.ByteString' * 'Data.ByteString.Lazy.ByteString' * 'Data.Text.Text' * 'Data.Text.Lazy.Text'+* 'Data.Text.Lazy.Text'+* 'Data.Map.Map' -By default the most economical but less exhaustive series are provided.-You may want to create your own instances for your own tests if this setting-doesn't apply for your own tests. Check the utilities in the other modules-in this package to create custom 'Series'.+By default the most exhaustive series are provided which can lead to+combinatorial explosion if you are not careful. In such case, you may want to+use the functions provided in the other modules in this package to create your+own custom series. -Make sure the module where you import these instances is not meant to be-imported, otherwise the orphan instances might create issues.+Make sure the module where you import these instances will not be imported,+otherwise you might get conflicts between orphan instances defined in different+modules. -} module Test.SmallCheck.Series.Instances () where #if !MIN_VERSION_base(4,8,0) import Control.Applicative ((<$>)) #endif+import Data.Int+import Data.Word import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL import qualified Data.Text as T@@ -31,14 +45,59 @@ import qualified Data.Map as Map import Test.SmallCheck.Series +instance Monad m => Serial m Int8 where+ series = (fromIntegral :: Int -> Int8) <$> series+instance Monad m => CoSerial m Int8 where+ coseries rs = (. (fromIntegral :: Int8 -> Int)) <$> coseries rs -import Test.SmallCheck.Series.ByteString as Series.ByteString-import Test.SmallCheck.Series.ByteString.Lazy as Series.ByteString.Lazy-import Test.SmallCheck.Series.Text as Series.Text-import Test.SmallCheck.Series.Text.Lazy as Series.Text.Lazy+instance Monad m => Serial m Int16 where+ series = (fromIntegral :: Int -> Int16) <$> series+instance Monad m => CoSerial m Int16 where+ coseries rs = (. (fromIntegral :: Int16 -> Int)) <$> coseries rs +instance Monad m => Serial m Int32 where+ series = (fromIntegral :: Int -> Int32) <$> series+instance Monad m => CoSerial m Int32 where+ coseries rs = (. (fromIntegral :: Int32 -> Int)) <$> coseries rs++instance Monad m => Serial m Int64 where+ series = (fromIntegral :: Int -> Int64) <$> series+instance Monad m => CoSerial m Int64 where+ coseries rs = (. (fromIntegral :: Int64 -> Int)) <$> coseries rs++instance Monad m => Serial m Word where+ series = generate $ \d -> take (d+1) [0..maxBound]+instance Monad m => CoSerial m Word where+ coseries rs =+ alts0 rs >>- \z ->+ alts1 rs >>- \f ->+ return $ \w ->+ if w > 0+ then f (w-1)+ else z++instance Monad m => Serial m Word8 where+ series = (fromIntegral :: Word -> Word8) <$> series+instance Monad m => CoSerial m Word8 where+ coseries rs = (. (fromIntegral :: Word8 -> Word)) <$> coseries rs++instance Monad m => Serial m Word16 where+ series = (fromIntegral :: Word -> Word16) <$> series+instance Monad m => CoSerial m Word16 where+ coseries rs = (. (fromIntegral :: Word16 -> Word)) <$> coseries rs++instance Monad m => Serial m Word32 where+ series = (fromIntegral :: Word -> Word32) <$> series+instance Monad m => CoSerial m Word32 where+ coseries rs = (. (fromIntegral :: Word32 -> Word)) <$> coseries rs++instance Monad m => Serial m Word64 where+ series = (fromIntegral :: Word -> Word64) <$> series+instance Monad m => CoSerial m Word64 where+ coseries rs = (. (fromIntegral :: Word64 -> Word)) <$> coseries rs+ instance Monad m => Serial m B.ByteString where- series = Series.ByteString.replicateA+ series = cons0 B.empty \/ cons2 B.cons instance Monad m => CoSerial m B.ByteString where coseries rs = alts0 rs >>- \y ->@@ -48,7 +107,7 @@ Just (b,bs') -> f (B.singleton b) bs' instance Monad m => Serial m BL.ByteString where- series = Series.ByteString.Lazy.replicateA+ series = cons0 BL.empty \/ cons2 BL.cons instance Monad m => CoSerial m BL.ByteString where coseries rs = alts0 rs >>- \y ->@@ -58,7 +117,7 @@ Just (b,bs') -> f (BL.singleton b) bs' instance Monad m => Serial m T.Text where- series = Series.Text.replicateA+ series = cons0 T.empty \/ cons2 T.cons instance Monad m => CoSerial m T.Text where coseries rs = alts0 rs >>- \y ->@@ -68,7 +127,7 @@ Just (b,bs') -> f (T.singleton b) bs' instance Monad m => Serial m TL.Text where- series = Series.Text.Lazy.replicateA+ series = cons0 TL.empty \/ cons2 TL.cons instance Monad m => CoSerial m TL.Text where coseries rs = alts0 rs >>- \y ->
Test/SmallCheck/Series/Utils.hs view
@@ -1,3 +1,6 @@+{-|+Extra utility functions to manipulate 'Series'.+-} module Test.SmallCheck.Series.Utils ( -- * Zipping@@ -37,8 +40,8 @@ -- | /One-to-One/ zipping of 3 'MonadLogic' instances. You can use for -- 'Test.SmallCheck.Series' like this: ----- >>> list 2 $ zipLogic3 (series :: Series Identity Char) (series :: Series Identity Int) (series :: Series Identity Text)--- [('a',0,""),('b',1,"a"),('c',-1,"aa")]+-- >>> list 3 $ zipLogic3 (series :: Series Identity Char) (series :: Series Identity Int) (series :: Series Identity Text)+-- [('a',0,""),('b',1,"a"),('c',-1,"b"),('d',2,"aa")] -- Thanks to Roman Cheplyaka: https://groups.google.com/d/msg/haskell-tasty/k0dXCx9EBsc/XYkCTjYKqswJ zipLogic3 :: MonadLogic m => m a -> m b -> m c -> m (a, b, c)
smallcheck-series.cabal view
@@ -1,5 +1,5 @@ name: smallcheck-series-version: 0.4+version: 0.5 synopsis: Extra SmallCheck series and utilities description: Orphan@@ -32,12 +32,12 @@ Test.SmallCheck.Series.Text.Lazy Test.SmallCheck.Series.Utils build-depends: base >=4.6 && <4.9,- bytestring >=0.10.0,+ bytestring >=0.10.0.2, containers >=0.5.0.0, text >=0.11.3, transformers >=0.3.0.0, logict >=0.6.0.2,- smallcheck >=1.1+ smallcheck >=1.1.1 test-suite doctests default-language: Haskell2010