hedgehogqa / haskell-hedgehog

Release with confidence, state-of-the-art property testing for Haskell.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Linear ranges don't produce large values

DigitalBrains1 opened this issue · comments

I don't think PR #405 achieved the intended result. It was intended to make the maximum value occur more often, but instead, for larger values, it does not occur at all anymore. Large numbers are 1% too small, getting worse the larger the range is.

With commit 0371468, the parent of PR #405, we see this behaviour:

$ cabal repl -w ghc-8.10 hedgehog
[...]
>>> import Hedgehog.Internal.Range
>>> import Data.Int
>>> scaleLinear 99 0 4 :: Integer
4
>>> bounds 99 (linearBounded :: Range Int8)
(-128,127)
>>> scaleLinear 99 0 100 :: Integer
100
>>> scaleLinear 99 0 10000 :: Integer
10000

I picked the 4 because that is used in the PR, and the Int8 is from the Haddock for Hedgehog, with the Haddock still to this day noting this unsurprising result of (-128,127).

WIth commit 06eb474, that is the merge of the PR, this becomes:

>>> scaleLinear 99 0 4 :: Integer
4
>>> bounds 99 (linearBounded :: Range Int8)
(-127,126)
>>> scaleLinear 99 0 100 :: Integer
99
>>> scaleLinear 99 0 10000 :: Integer
9900

Before PR #405, the code used to multiply by 99 and divide by 99.

The new code adds a constant, multiplies by 99 and divides by 100. But there is no constant additive value that can compensate for the larger division; as values get larger the division will dominate more and more. If an addition is wanted, it will need to be proportional to the values involved.

Thank you, @DigitalBrains1. This is interesting. I commented in 06eb474#r142392749.