gray-code 0.2.1 → 0.2.2
raw patch · 5 files changed
+45/−23 lines, 5 filesdep +QuickCheckdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: QuickCheck
Dependency ranges changed: base
API changes (from Hackage documentation)
- Codec.Binary.Gray.Bits: binary :: Bits a => a -> a
+ Codec.Binary.Gray.Bits: binary :: (Bits a, Num a) => a -> a
- Codec.Binary.Gray.Bits: gray :: Bits a => a -> a
+ Codec.Binary.Gray.Bits: gray :: (Bits a, Num a) => a -> a
- Codec.Binary.Gray.Bits: showBits :: Bits a => a -> String
+ Codec.Binary.Gray.Bits: showBits :: (Bits a, Num a) => a -> String
- Codec.Binary.Gray.List: fromList :: Bits b => [Bool] -> b
+ Codec.Binary.Gray.List: fromList :: (Bits b, Num b) => [Bool] -> b
- Codec.Binary.Gray.List: toList :: Bits b => b -> [Bool]
+ Codec.Binary.Gray.List: toList :: (Bits b, Num b) => b -> [Bool]
- Codec.Binary.Gray.List: toList' :: Bits b => b -> [Bool]
+ Codec.Binary.Gray.List: toList' :: (Bits b, Num b) => b -> [Bool]
Files
- Codec/Binary/Gray/Bits.hs +7/−7
- Codec/Binary/Gray/List.hs +4/−4
- Codec/Binary/Gray_props.hs +4/−4
- gray-code.cabal +12/−8
- test.hs +18/−0
Codec/Binary/Gray/Bits.hs view
@@ -17,9 +17,9 @@ , shiftL, shiftR, complement, xor, (.&.), (.|.), isSigned) import qualified Codec.Binary.Gray.List as L- + -- | Right shift without extension of the sign bit (reset it to zero).-shiftR' :: (Bits a) => a -> Int -> a+shiftR' :: (Bits a, Num a) => a -> Int -> a shiftR' n 0 = n shiftR' n s | isSigned n && signum n == -1 =@@ -28,17 +28,17 @@ | otherwise = shiftR n s -- | Convert an integer number from binary to Gray code.--- +-- -- 'gray' is undefined for negative numbers of types that do not have -- fixed bitsize, e.g. for negative 'Integer's.-gray :: (Bits a) => a -> a+gray :: (Bits a, Num a) => a -> a gray n = n `xor` (shiftR' n 1) -- | Convert an integer number from Gray code to binary.--- +-- -- 'binary' is undefined for types that do not have fixed bitsize, -- e.g. for 'Integer'.-binary :: (Bits a) => a -> a+binary :: (Bits a, Num a) => a -> a binary 0 = 0 binary n = binary' mask0 n (copyMSB n)@@ -61,5 +61,5 @@ -- | Render binary code as a string of @0@s and @1@s. -- For example, @(42::Int8)@ is formatted as @101010@.-showBits :: (Bits a) => a -> String+showBits :: (Bits a, Num a) => a -> String showBits = L.showBits . L.toList
Codec/Binary/Gray/List.hs view
@@ -34,10 +34,10 @@ -- | Convert a number to a list of bits in usual binary encoding (most -- significant bit last). Truncates unset major bits.--- +-- -- This function is undefined for negative numbers of types that do not -- have fixed bitsize, like 'Integer'.-toList :: (Bits b) => b -> [Bool]+toList :: (Bits b, Num b) => b -> [Bool] toList 0 = [] toList i | isSigned i && signum i == (-1) =@@ -52,11 +52,11 @@ -- -- Like 'toList', but returns all unset major bits too. So the length -- of the output is always the same length as @bitSize i@.-toList' :: (Bits b) => b -> [Bool]+toList' :: (Bits b, Num b) => b -> [Bool] toList' i = map (testBit i) [0..bitSize i - 1] -- | Convert a list of bits in binary encoding to a number.-fromList :: (Bits b) => [Bool] -> b+fromList :: (Bits b, Num b) => [Bool] -> b fromList = sum . map fst . filter snd . zip (map (2^) [0..]) -- | Render a list of bits as a string of @0@s and @1@s.
Codec/Binary/Gray_props.hs view
@@ -45,7 +45,7 @@ let i = (arbitrary :: Gen Int) in forAll i succ_test -succ_test :: (Bits a) => a -> Bool+succ_test :: (Bits a, Num a) => a -> Bool succ_test = \i -> let n2g = L.gray . L.toList g1 = n2g i@@ -78,12 +78,12 @@ prop_bits_gray_succ_Int = label "hamming x (x+1) == 1 [Int]" $ forAll (arbitrary :: Gen Int) $ \i -> (hammingBits `on` B.gray) i (i+1) == 1- + prop_bits_gray_succ_Integer = label "hamming x (x+1) == 1 [Integer]" $ forAll (arbitrary :: Gen (NonNegative Integer)) $ \(NonNegative i) -> (hammingBits `on` B.gray) i (i+1) == 1- -hammingBits :: (Bits a) => a -> a -> Int++hammingBits :: (Bits a, Num a) => a -> a -> Int hammingBits = hamming `on` L.toList ---
gray-code.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version: 0.2.1+Version: 0.2.2 -- A short (one-line) description of the package. Synopsis: Gray code encoder/decoder.@@ -23,7 +23,7 @@ @Bits@ is the default implementation. -- URL for the project homepage or repository.-Homepage: http://bitbucket.org/jetxee/hs-gray-code+Homepage: http://bitbucket.org/astanin/hs-gray-code -- The license under which the package is released. License: BSD3@@ -39,7 +39,7 @@ Maintainer: s.astanin@gmail.com -- A copyright notice.--- Copyright: +-- Copyright: -- Stability of the pakcage (experimental, provisional, stable...) Stability: Experimental@@ -54,7 +54,7 @@ Codec/Binary/Gray_props.hs -- Constraint on the version of Cabal needed to build this package.-Cabal-version: >=1.2+Cabal-version: >=1.8 Library@@ -67,10 +67,14 @@ -- Packages needed in order to build this package. Build-depends: base >= 3 && < 5- + -- Modules not exported by this package. -- Other-modules:- + -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.- -- Build-tools: - + -- Build-tools:++Test-Suite test-qc+ type: exitcode-stdio-1.0+ main-is: test.hs+ build-depends: base, QuickCheck >= 2
+ test.hs view
@@ -0,0 +1,18 @@+module Main where++import Control.Monad (unless)+import Test.QuickCheck.Test (verboseCheckResult, quickCheckResult, isSuccess)+import System.Exit (exitFailure)+import System.Environment (getArgs)++import Codec.Binary.Gray_props++main = do+ args <- getArgs+ let testsResult = if (("-v" `elem` args) || ("--verbose" `elem` args))+ then verboseCheckResult+ else quickCheckResult+ result <- testsResult all_props+ unless (isSuccess result) $ do+ print result+ exitFailure