| 1 | Thu Aug 21 20:59:48 PDT 2008 Patrick Perry <patperry@stanford.edu> |
|---|
| 2 | * Fix bug in variant |
|---|
| 3 | |
|---|
| 4 | Currently, "variant" will throw an execption if given a negative argument. |
|---|
| 5 | Moreover, the runtime of variant is linear in the argument. Both of these |
|---|
| 6 | issues manifest in the following properties, which will either hang or |
|---|
| 7 | throw an exception, depending on the platform: |
|---|
| 8 | |
|---|
| 9 | \begin{code} |
|---|
| 10 | import Test.QuickCheck |
|---|
| 11 | import Text.Show.Functions |
|---|
| 12 | |
|---|
| 13 | prop_ok (f :: Double -> Double) = |
|---|
| 14 | f (-5.5) `seq` True |
|---|
| 15 | |
|---|
| 16 | prop_bug (f :: Double -> Double) = |
|---|
| 17 | f (-5.6) `seq` True |
|---|
| 18 | |
|---|
| 19 | main = do |
|---|
| 20 | putStr "prop_ok:\t" >> quickCheck prop_ok |
|---|
| 21 | putStr "prop_bug:\t" >> quickCheck prop_bug |
|---|
| 22 | \end{code} |
|---|
| 23 | |
|---|
| 24 | This patch backports the version of variant in QuickCheck2. It avoids the |
|---|
| 25 | negativity problem and makes the run-time logarithmic in the size of the |
|---|
| 26 | argument. |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | New patches: |
|---|
| 30 | |
|---|
| 31 | [Fix bug in variant |
|---|
| 32 | Patrick Perry <patperry@stanford.edu>**20080822035948 |
|---|
| 33 | |
|---|
| 34 | Currently, "variant" will throw an execption if given a negative argument. |
|---|
| 35 | Moreover, the runtime of variant is linear in the argument. Both of these |
|---|
| 36 | issues manifest in the following properties, which will either hang or |
|---|
| 37 | throw an exception, depending on the platform: |
|---|
| 38 | |
|---|
| 39 | \begin{code} |
|---|
| 40 | import Test.QuickCheck |
|---|
| 41 | import Text.Show.Functions |
|---|
| 42 | |
|---|
| 43 | prop_ok (f :: Double -> Double) = |
|---|
| 44 | f (-5.5) `seq` True |
|---|
| 45 | |
|---|
| 46 | prop_bug (f :: Double -> Double) = |
|---|
| 47 | f (-5.6) `seq` True |
|---|
| 48 | |
|---|
| 49 | main = do |
|---|
| 50 | putStr "prop_ok:\t" >> quickCheck prop_ok |
|---|
| 51 | putStr "prop_bug:\t" >> quickCheck prop_bug |
|---|
| 52 | \end{code} |
|---|
| 53 | |
|---|
| 54 | This patch backports the version of variant in QuickCheck2. It avoids the |
|---|
| 55 | negativity problem and makes the run-time logarithmic in the size of the |
|---|
| 56 | argument. |
|---|
| 57 | |
|---|
| 58 | ] { |
|---|
| 59 | hunk ./Test/QuickCheck.hs 99 |
|---|
| 60 | -variant v (Gen m) = Gen (\n r -> m n (rands r !! (v+1))) |
|---|
| 61 | +variant v (Gen m) = Gen (\n r -> m n (rands r v)) |
|---|
| 62 | hunk ./Test/QuickCheck.hs 101 |
|---|
| 63 | - rands r0 = r1 : rands r2 where (r1, r2) = split r0 |
|---|
| 64 | + rands r0 0 = r0 |
|---|
| 65 | + rands r0 n = let (r1,r2) = split r0 |
|---|
| 66 | + (n',s) = n `quotRem` 2 |
|---|
| 67 | + in case s of |
|---|
| 68 | + 0 -> rands r1 n' |
|---|
| 69 | + _ -> rands r2 n' |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | Context: |
|---|
| 73 | |
|---|
| 74 | [Make QuickCheck work with extensible exceptions |
|---|
| 75 | Ian Lynagh <igloo@earth.li>**20080805125743] |
|---|
| 76 | [TAG GHC 6.8.3 release |
|---|
| 77 | Ian Lynagh <igloo@earth.li>**20080619124351] |
|---|
| 78 | [TAG 2008-06-06 |
|---|
| 79 | Ian Lynagh <igloo@earth.li>**20080605235803] |
|---|
| 80 | Patch bundle hash: |
|---|
| 81 | 38f20a1de98fa973219f7379d25d33b0d399dd0b |
|---|