@@ -82,6 +82,13 @@ tests =
8282 , testProperty "Word64" (prop_putget_list_simple :: W [Word64] -> Property)
8383 ]
8484
85+ , testGroup "prop_putget_applicative_with_bitreq"
86+ [ testProperty "Word8" (prop_putget_applicative_with_bitreq :: W [(Word8,Word8,Word8)] -> Property)
87+ , testProperty "Word16" (prop_putget_applicative_with_bitreq :: W [(Word16,Word16,Word16)] -> Property)
88+ , testProperty "Word32" (prop_putget_applicative_with_bitreq :: W [(Word32,Word32,Word32)] -> Property)
89+ , testProperty "Word64" (prop_putget_applicative_with_bitreq :: W [(Word64,Word64,Word64)] -> Property)
90+ ]
91+
8592 , testGroup "prop_putget_list_with_bitreq"
8693 [ testProperty "Word8" (prop_putget_list_with_bitreq :: W [Word8] -> Property)
8794 , testProperty "Word16" (prop_putget_list_with_bitreq :: W [Word16] -> Property)
@@ -129,6 +136,18 @@ prop_putget_list_with_bitreq (W ws) = property $
129136 where
130137 bitlist = map bitreq ws
131138
139+prop_putget_applicative_with_bitreq :: (BinaryBit a, Num a, Bits a, Ord a) => W [(a,a,a)] -> Property
140+prop_putget_applicative_with_bitreq (W ts) = property $
141+ let p = mapM_ (\(a,b,c) -> do putBits (bitreq a) a
142+ putBits (bitreq b) b
143+ putBits (bitreq c) c) ts
144+ g = mapM (\(a,b,c) -> (,,) <$> getBits a <*> getBits b <*> getBits c) bitlist
145+ lbs = runPut (runBitPut p)
146+ ts' = runGet (runBitGet g) lbs
147+ in ts == ts'
148+ where
149+ bitlist = map (\(a,b,c) -> (bitreq a, bitreq b, bitreq c)) ts
150+
132151-- | Write bits using this library, and read them back using the binary
133152-- library.
134153prop_bitput_with_get_from_binary :: (BinaryBit a, Binary a, Storable a, Eq a) => W [a] -> Property
@@ -235,14 +254,16 @@ shrinker w = [ w `shiftR` 1 -- try to make everything roughly half size
235254
236255data W a = W { unW :: a } deriving (Show, Eq, Ord)
237256
257+arbitraryW :: (Arbitrary (W a)) => Gen a
258+arbitraryW = unW <$> arbitrary
259+
260+shrinkW :: (Arbitrary (W a)) => a -> [a]
261+shrinkW x = unW <$> shrink (W x)
262+
238263instance Arbitrary (W Bool) where
239264 arbitrary = W <$> arbitrary
240265 shrink = map W <$> shrink . unW
241266
242−instance (Arbitrary (W a)) => Arbitrary (W [a]) where
243− arbitrary = W . map unW <$> arbitrary
244− shrink = map (W . map unW) <$> mapM shrink . map W . unW
245−
246267instance Arbitrary (W Word8) where
247268 arbitrary = W <$> choose (minBound, maxBound)
248269 shrink = map W . shrinker . unW
@@ -263,6 +284,18 @@ instance Arbitrary B.ByteString where
263284 arbitrary = B.pack <$> arbitrary
264285 shrink bs = B.pack <$> shrink (B.unpack bs)
265286
287+instance (Arbitrary (W a)) => Arbitrary (W [a]) where
288+ arbitrary = W . map unW <$> arbitrary
289+ shrink = map (W . map unW) <$> mapM shrink . map W . unW
290+
291+instance (Arbitrary (W a), Arbitrary (W b)) => Arbitrary (W (a,b)) where
292+ arbitrary = (W .) . (,) <$> arbitraryW <*> arbitraryW
293+ shrink (W (a,b)) = (W .) . (,) <$> shrinkW a <*> shrinkW b
294+
295+instance (Arbitrary (W a), Arbitrary (W b), Arbitrary (W c)) => Arbitrary (W (a,b,c)) where
296+ arbitrary = ((W .) .) . (,,) <$> arbitraryW <*> arbitraryW <*> arbitraryW
297+ shrink (W (a,b,c)) = ((W .) .) . (,,) <$> shrinkW a <*> shrinkW b <*> shrinkW c
298+
266299integralRandomR :: (Integral a, RandomGen g) => (a,a) -> g -> (a,g)
267300integralRandomR (a,b) g = case randomR (fromIntegral a :: Integer,
268301 fromIntegral b :: Integer) g of