bits-extras 0.1.2 → 0.1.3
raw patch · 3 files changed
+110/−4 lines, 3 filesdep +HUnitdep +QuickCheckdep +test-frameworksetup-changednew-component:exe:testPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: HUnit, QuickCheck, test-framework, test-framework-hunit, test-framework-quickcheck2
API changes (from Hackage documentation)
- Data.Bits.Extras: byteSwap :: (ExtraBits x) => x -> x
+ Data.Bits.Extras: byteSwap :: ExtraBits x => x -> x
- Data.Bits.Extras: class (Bits x) => ExtraBits x
+ Data.Bits.Extras: class Bits x => ExtraBits x
- Data.Bits.Extras: leadingZeros :: (ExtraBits x) => x -> Word32
+ Data.Bits.Extras: leadingZeros :: ExtraBits x => x -> Word32
- Data.Bits.Extras: lowestBitPlus1 :: (ExtraBits x) => x -> Word32
+ Data.Bits.Extras: lowestBitPlus1 :: ExtraBits x => x -> Word32
- Data.Bits.Extras: parity :: (ExtraBits x) => x -> Word32
+ Data.Bits.Extras: parity :: ExtraBits x => x -> Word32
- Data.Bits.Extras: populationCount :: (ExtraBits x) => x -> Word32
+ Data.Bits.Extras: populationCount :: ExtraBits x => x -> Word32
- Data.Bits.Extras: trailingZeros :: (ExtraBits x) => x -> Word32
+ Data.Bits.Extras: trailingZeros :: ExtraBits x => x -> Word32
Files
- Setup.hs +18/−1
- bits-extras.cabal +37/−3
- test/test.hs +55/−0
Setup.hs view
@@ -1,2 +1,19 @@+{-# LANGUAGE CPP #-} import Distribution.Simple-main = defaultMain+import Distribution.PackageDescription+import Distribution.Simple.LocalBuildInfo(LocalBuildInfo, buildDir)+import System.Cmd(system)++ps :: String+#if mingw32_HOST_OS || mingw32_TARGET_OS+ps = ['\\']+#else+ps = ['/']+#endif++main = defaultMainWithHooks hooks+ where hooks = simpleUserHooks { runTests = runTests' }++runTests' :: Args -> Bool -> PackageDescription -> LocalBuildInfo -> IO ()+runTests' _ _ _ lbi = system testprog >> return ()+ where testprog = (buildDir lbi) ++ ps ++ "test" ++ ps ++ "test"
bits-extras.cabal view
@@ -1,5 +1,5 @@ Name: bits-extras-Version: 0.1.2+Version: 0.1.3 License: BSD3 License-File: License.txt Maintainer: Gabriel Wicke <wicke@wikidev.net>@@ -30,15 +30,23 @@ * <http://hackage.haskell.org/trac/ghc/ticket/3563> . * <http://hackage.haskell.org/trac/ghc/ticket/4102>+ .+ /Changes/:+ .+ * 0.1.3: Added a first test and tweaked documentation. No functional changes.+ .+ * 0.1.2: Moved the 'Data.Bits.Atomic' module to the package @bits-atomic@.+ Those operations do not depend on libgcc_s and should work wherever GCC 4.X+ is available. Link to @bits-atomic@ on hackage:+ <http://hackage.haskell.org/package/bits-atomic> Category: Data Stability: experimental Build-Type: Simple Cabal-Version: >= 1.6---Extra-Source-Files: cbits/bitops-gcc.c cbits/bitops-gcc.h+Extra-Source-Files: cbits/bitops-gcc.c cbits/bitops-gcc.h Source-Repository head type: mercurial location: http://dev.wikidev.net/hg/bits-extras/---extra-tmp-files: cbits/bitops-gcc.h library Exposed-Modules: Data.Bits.Extras Build-Depends: base >= 4 && < 6@@ -58,3 +66,29 @@ --Includes: bitops-gcc.h --LD-Options: -flto --hs-source-dirs: .++flag test+ description: Build test program.+ default: False++Executable test+ if flag(test)+ buildable: True+ build-depends: + base >= 4 && < 6, + QuickCheck, + HUnit,+ test-framework-quickcheck2,+ test-framework-hunit,+ test-framework+ else+ buildable: False+ hs-source-dirs: ., test+ other-modules: Data.Bits.Extras+ main-is: test.hs+ --GHC-Options: -O2 -threaded -fhpc+ GHC-Options: -O2 -threaded+ GHC-Prof-Options: -auto-all++ Include-Dirs: cbits+ C-Sources: cbits/bitops-gcc.c
+ test/test.hs view
@@ -0,0 +1,55 @@+{-# LANGUAGE ForeignFunctionInterface, RankNTypes, FlexibleContexts, ExistentialQuantification #-}+-- Test framework imports+import Test.Framework (defaultMain, testGroup, Test)+import Test.Framework.Providers.HUnit+import Test.HUnit hiding (Test, Testable)+import Test.Framework.Providers.QuickCheck2+import Test.QuickCheck++-- Code to test+import Data.Bits.Extras+import Data.Word+import Data.Int+import Data.Bits++tests :: [Test]+tests = [ testGroup "Test Cases" + [ testCase "trailingZeros" test_trailingZeros_all+ ]+ ]++main :: IO ()+main = defaultMain tests++-- TODO: Use Quickcheck to produce arbitrary values?+testPattern :: Integral a => a+testPattern = 0xdeadbeef+++type PolyTest = (ExtraBits a, Integral a, Bounded a) => a -> Assertion++testTypes :: PolyTest -> Assertion+testTypes t = do+ t (testPattern :: Int)+ t (testPattern :: Word)+ t (testPattern :: Int8)+ t (testPattern :: Int16)+ t (testPattern :: Int32)+ t (testPattern :: Int64)+ t (testPattern :: Word8)+ t (testPattern :: Word16)+ t (testPattern :: Word32)+ t (testPattern :: Word64)++test_trailingZeros :: PolyTest+test_trailingZeros i = do+ let t0 = i - i+ -- No test for 0, as the result would be undefined+ trailingZeros (t0 + 1) @?= fromIntegral t0+ trailingZeros (t0 + 3) @?= fromIntegral t0+ trailingZeros (t0 + 2) @?= fromIntegral t0 + 1+ let hbitshift = bitSize i - 1+ hbitset = (t0 + 1) `shiftL` hbitshift+ assertEqual "High bit set" (fromIntegral hbitset) hbitshift+test_trailingZeros_all :: Assertion+test_trailingZeros_all = testTypes test_trailingZeros