largeword 1.0.5 → 1.1.0
raw patch · 3 files changed
+32/−2 lines, 3 filesdep +binarydep +bytestring
Dependencies added: binary, bytestring
Files
- Data/LargeWord.hs +7/−0
- Tests/Properties.hs +20/−0
- largeword.cabal +5/−2
Data/LargeWord.hs view
@@ -31,6 +31,9 @@ import Numeric import Data.Char +import Control.Applicative ((<$>), (<*>))+import Data.Binary (Binary, put, get)+ -- Keys have certain capabilities. class LargeWord a where@@ -233,6 +236,10 @@ pred (LargeKey l h) = LargeKey (pred l) h succ (LargeKey l h) = if l == maxBound then LargeKey 0 (succ h) else LargeKey (succ l) h++instance (Binary a, Binary b) => Binary (LargeKey a b) where+ put (LargeKey lo hi) = put hi >> put lo+ get = flip LargeKey <$> get <*> get type Word96 = LargeKey Word32 Word64 type Word128 = LargeKey Word64 Word64
Tests/Properties.hs view
@@ -8,6 +8,8 @@ import Data.LargeWord import Data.Bits import Control.Monad+import Data.Binary (encode, decode, Binary)+import qualified Data.ByteString.Lazy as LZ instance (Arbitrary a, Arbitrary b) => Arbitrary (LargeKey a b) where arbitrary = liftM2 LargeKey arbitrary arbitrary@@ -17,10 +19,28 @@ u1 = shiftR (18446744073709551616 :: Word128) 64 @?= 1 +encodeDecode :: (Binary a, Binary b, Eq a, Eq b) => LargeKey a b -> Bool+encodeDecode word = decode encoded == word+ where+ encoded = encode word+ {-# NOINLINE encoded #-}++correctEncoding = (decode . LZ.pack)+ [0,0,0,0,0,0,0,0,50,89,125,125,237,119,73,240,217,12,178,101,235,8,44,221,50,122,244,125,115,181,239,78]+ @?=+ (1234567891234567891234567812345678123456781234567812345678 :: Word256)+ tests :: [Test] tests = [ testProperty "largeword shift left then right" pShiftRightShiftLeft , testCase "largeword shift 2^64 by 2^64" u1+ , testCase "big-endian encoding" correctEncoding+ , testProperty "Word96 encode/decode loop" (encodeDecode::Word96 -> Bool)+ , testProperty "Word128 encode/decode loop" (encodeDecode::Word128 -> Bool)+ , testProperty "Word160 encode/decode loop" (encodeDecode::Word160 -> Bool)+ , testProperty "Word192 encode/decode loop" (encodeDecode::Word192 -> Bool)+ , testProperty "Word224 encode/decode loop" (encodeDecode::Word224 -> Bool)+ , testProperty "Word256 encode/decode loop" (encodeDecode::Word256 -> Bool) ] main = defaultMain tests
largeword.cabal view
@@ -1,5 +1,5 @@ name: largeword-version: 1.0.5+version: 1.1.0 license: BSD3 copyright: Dominic Steinitz <dominic@steinitz.org> author: Dominic Steinitz <dominic@steinitz.org>@@ -21,7 +21,8 @@ location: https://github.com/idontgetoutmuch/largeword Library- Build-Depends: base >= 4.0 && < 5+ Build-Depends: base >= 4.0 && < 5,+ binary exposed-modules: Data.LargeWord Test-suite tests@@ -29,6 +30,8 @@ Hs-source-dirs: Tests Main-is: Properties.hs Build-depends: base >= 4.0 && < 5,+ binary,+ bytestring, test-framework >= 0.3.3 && < 0.9, test-framework-quickcheck2 >= 0.2.9 && < 0.4, test-framework-hunit >= 0.2.6 && < 0.4,