git.iko.soy/typeable/attoparsec
on master help sign in
Add QuickCheck support
commitbf6d15e226116fdd76724aa3e14c093e83ce6b76 authorBryan O'Sullivan <bos@serpentine.com> dateSat 27 Sep 2008, 16:51 (18 years ago) parent161284e
2 files changed+30
tests/Makefile+5 tests/TestFastSet.hs+25
tests/Makefilenew file+5
@@ -0,0 +1,5 @@
1+tests: TestFastSet.out
2+
3+%.out: %.hs
4+ runghc $< > $<.tmp
5+ mv $<.tmp $@
tests/TestFastSet.hsnew file+25
@@ -0,0 +1,25 @@
1+module TestFastSet where
2+
3+import Data.Word (Word8)
4+import qualified Data.ParserCombinators.Attoparsec.FastSet as F
5+import System.Random (Random(..), RandomGen)
6+import Test.QuickCheck
7+
8+integralRandomR :: (Integral a, RandomGen g) => (a, a) -> g -> (a, g)
9+integralRandomR (a,b) g = case randomR (fromIntegral a :: Int,
10+ fromIntegral b :: Int) g
11+ of (x,g') -> (fromIntegral x, g')
12+
13+instance Random Word8 where
14+ randomR = integralRandomR
15+ random = randomR (minBound,maxBound)
16+
17+instance Arbitrary Word8 where
18+ arbitrary = choose (minBound, maxBound)
19+
20+prop_AllMembers s =
21+ let set = F.fromList s
22+ in all (`F.memberWord8` set) s
23+
24+main = do
25+ quickCheck prop_AllMembers