@@ -10,62 +10,72 @@ import qualified Test.QuickCheck.Random as QC
10
10
import Trace.Hpc.Reflect (examineTix )
11
11
import Trace.Hpc.Tix (Tix (.. ), TixModule (.. ))
12
12
13
- testUntilSameQCMany :: (Traversable t , QC. Testable a ) => Int -> t a -> IO (t (Int , Maybe Integer ))
13
+ testUntilSameQCMany :: (Traversable t , QC. Testable a ) => Int -> t a -> IO (t (KudzuResult Integer ))
14
14
testUntilSameQCMany howMany ts = do
15
- mapM (testUntilSameQC howMany) ts
15
+ mapM (testUntilSameQC howMany) ts
16
16
17
17
-- | QuickCheck
18
- testUntilSameQC :: QC. Testable a => Int -> a -> IO (Int , Maybe Integer )
18
+ testUntilSameQC :: ( QC. Testable a ) => Int -> a -> IO (KudzuResult Integer )
19
19
testUntilSameQC n testable = do
20
- let rs = map (examineAndCount' testable) [0 .. n]
21
- r1 <- head rs
22
- grabUntilNSame 0 n n (tail rs) r1
20
+ let rs = map (examineAndCount' testable) [0 .. n]
21
+ r1 <- head rs
22
+ grabUntilNSame 0 n n (tail rs) r1
23
23
24
- examineAndCount' :: QC. Testable prop => prop -> Int -> IO Integer
24
+ examineAndCount' :: ( QC. Testable prop ) => prop -> Int -> IO Integer
25
25
examineAndCount' v size = do
26
- qcg <- QC. newQCGen
27
- QC. quickCheckWith (QC. stdArgs { QC. replay = Just (qcg, size)}) (QC. withMaxSuccess 1 v)
28
- tixModuleCount <$> examineTix
26
+ qcg <- QC. newQCGen
27
+ QC. quickCheckWith (QC. stdArgs{ QC. replay = Just (qcg, size)}) (QC. withMaxSuccess 1 v)
28
+ tixModuleCount <$> examineTix
29
29
30
30
-- | Hedgehog
31
- testUntilSameHHMany :: Traversable t => Int -> t HH. Property -> IO (t (Int , Maybe Integer ))
31
+ testUntilSameHHMany :: ( Traversable t ) => Int -> t HH. Property -> IO (t (KudzuResult Integer ))
32
32
testUntilSameHHMany howMany ps = do
33
- mapM (testUntilSameHH howMany) ps
33
+ mapM (testUntilSameHH howMany) ps
34
34
35
- testUntilSameHH :: Int -> HH. Property -> IO (Int , Maybe Integer )
35
+ testUntilSameHH :: Int -> HH. Property -> IO (KudzuResult Integer )
36
36
testUntilSameHH n prop = do
37
- let rs = examineAndCountHH <$> repeat prop
38
- r1 <- head rs
39
- grabUntilNSame 0 n n (tail rs) r1
37
+ let rs = examineAndCountHH <$> repeat prop
38
+ r1 <- head rs
39
+ grabUntilNSame 0 n n (tail rs) r1
40
40
41
41
examineAndCountHH :: HH. Property -> IO Integer
42
42
examineAndCountHH prop = do
43
- passed <- HH. check prop
44
- unless passed $ error " property failed"
45
- tixModuleCount <$> examineTix
43
+ passed <- HH. check prop
44
+ unless passed $ error " property failed"
45
+ tixModuleCount <$> examineTix
46
46
47
47
-- | LeanCheck
48
- testUntilSameLCMany :: (Traversable t , LC. Testable a ) => Int -> t a -> IO (t (Int , Maybe Integer ))
48
+ testUntilSameLCMany :: (Traversable t , LC. Testable a ) => Int -> t a -> IO (t (KudzuResult Integer ))
49
49
testUntilSameLCMany howMany ts = do
50
- mapM (testUntilSameLC howMany) ts
50
+ mapM (testUntilSameLC howMany) ts
51
51
52
- testUntilSameLC :: LC. Testable a => Int -> a -> IO (Int , Maybe Integer )
52
+ testUntilSameLC :: ( LC. Testable a ) => Int -> a -> IO (KudzuResult Integer )
53
53
testUntilSameLC n testable = do
54
- let rs = examineAndCount <$> LC. results testable
55
- r1 <- head rs
56
- grabUntilNSame 0 n n (tail rs) r1
54
+ let rs = examineAndCount <$> LC. results testable
55
+ r1 <- head rs
56
+ grabUntilNSame 0 n n (tail rs) r1
57
57
58
58
examineAndCount :: ([String ], Bool ) -> IO Integer
59
- examineAndCount v = unless (snd v) (error $ unwords (" test failed with:" : fst v)) >> tixModuleCount <$> examineTix
59
+ examineAndCount v = unless (snd v) (error $ unwords (" test failed with:" : fst v)) >> tixModuleCount <$> examineTix
60
60
61
- grabUntilNSame :: (Monad m , Eq a ) => Int -> Int -> Int -> [m a ] -> a -> m (Int , Maybe a )
62
- grabUntilNSame c _ 0 _ z = pure (c, Just z)
63
- grabUntilNSame c _ _ [] _ = pure (c, Nothing )
61
+ data KudzuResult a = KFail Int | KSuccess Int a
62
+
63
+ {-
64
+ Keep running property tests until the "amount" of code coverage is the same for N iterations of one test.
65
+ orig: the number of iterations of a test that must have the same amount of code coverage before you give up and stop.
66
+ c: the number of iterations checked
67
+ n: countdown to the success case
68
+ -}
69
+ grabUntilNSame :: (Monad m , Eq a ) => Int -> Int -> Int -> [m a ] -> a -> m (KudzuResult a )
70
+ grabUntilNSame c _ 0 _ z = pure $ KSuccess c z -- we reached the desired window size
71
+ grabUntilNSame c _ _ [] _ = pure $ KFail c -- if we run out of list elements for test results, we're done
64
72
grabUntilNSame c orig n (a : as) z = do
65
- a' <- a
66
- if a' == z
67
- then grabUntilNSame (c + 1 ) orig (n - 1 ) as z
68
- else grabUntilNSame (c + 1 ) orig orig as a'
73
+ a' <- a
74
+ if a' == z -- is the count of regions covered from this run the same as last run?
75
+ then grabUntilNSame (c + 1 ) orig (n - 1 ) as z
76
+ else grabUntilNSame (c + 1 ) orig orig as a'
77
+
78
+ -- where go c n a z =
69
79
70
80
-- | How many regions were executed at least once for this module?
71
81
tixCount :: TixModule -> Integer
0 commit comments