[commit: packages/binary] master: Increase test coverage for Binary Natural instance. (916372c)
git at git.haskell.org
git at git.haskell.org
Mon Jun 1 08:47:53 UTC 2015
Repository : ssh://git@git.haskell.org/binary
On branch : master
Link : http://git.haskell.org/packages/binary.git/commitdiff/916372c846e50e84da0ce262f57c685be22f46ba
>---------------------------------------------------------------
commit 916372c846e50e84da0ce262f57c685be22f46ba
Author: Lennart Kolmodin <kolmodin at google.com>
Date: Sun May 31 16:41:04 2015 +0200
Increase test coverage for Binary Natural instance.
The arbitrarySizedNatural creates too small Naturals so we didn't test
all code paths. Use a custom generator to get bigger numbers.
>---------------------------------------------------------------
916372c846e50e84da0ce262f57c685be22f46ba
tests/QC.hs | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/tests/QC.hs b/tests/QC.hs
index b0b4c8f..addf185 100644
--- a/tests/QC.hs
+++ b/tests/QC.hs
@@ -358,10 +358,20 @@ main = defaultMain tests
------------------------------------------------------------------------
#ifdef HAS_NATURAL
--- | Until the QuickCheck library implements instance Arbitrary Natural,
--- we need this test.
prop_test_Natural :: Property
-prop_test_Natural = forAll (arbitrarySizedNatural :: Gen Natural) test
+prop_test_Natural = forAll (gen :: Gen Natural) test
+ where
+ gen :: Gen Natural
+ gen = do
+ b <- arbitrary
+ if b
+ then do
+ x <- arbitrarySizedNatural :: Gen Natural
+ -- arbitrarySizedNatural generates numbers smaller than
+ -- (maxBound :: Word64), so let's make them bigger to better test
+ -- the Binary instance.
+ return (x + fromIntegral (maxBound :: Word64))
+ else arbitrarySizedNatural
#endif
------------------------------------------------------------------------
More information about the ghc-commits
mailing list