-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The random selection doesn't appear to be very random #119
Comments
It is somewhat reversed #99: numbers being biased too much towards I'm going to prepare a reformed number generation analogous to char (but simpler) which should cover entire range, yet preferring some particular numbers. |
There needs to be a new api for requesting a quickcheck-controlled size value. Something that's appropriate for selecting the size of a datastructure to generate. I think I mostly use usize's Arbitrary impl for that at the moment. |
Experienced a problem with some tests: stratis-storage/stratisd@0f7838d, all u64 values were less than minimum required, so all testt were discarded. |
With current behaviour that is expected @mulkieran and you simply need a wrapper type that defines the distribution of values that you need. |
@bluss Can you give me an example? |
if anyone who understand this problem can give me some help, I'ld appreciate it. |
Something like this to make a wrapper type that puts a value inside using the regular extern crate quickcheck;
use quickcheck::Arbitrary;
use quickcheck::Gen;
extern crate rand;
use rand::{Rand, Rng};
#[derive(Copy, Clone, Debug)]
pub struct Random<T>(pub T);
impl<T> Arbitrary for Random<T>
where T: Rand + Clone + Send + 'static
{
fn arbitrary<G: Gen>(g: &mut G) -> Self {
Random(g.gen())
}
} |
Maybe it's time to make a change like #99, but for numbers?
That could make "sane default" for multiple varied uses. Obviously one could override the distribution to task-specific. |
I would always ask myself what Hypothesis (https://github.com/HypothesisWorks/hypothesis-python) does. But it might not be such a useful question for this problem in this situation. |
The Haskell implementation seems to first decide maximum bits the generated number has. Then generate a number within the range Current workaround would be setting environment variable |
@BurntSushi I'd like to hear your thoughts about following propositions addressing this issue.
*valid values for an integer type |
@maxbla Thanks for writing that out! I think that all seems pretty reasonable to me. |
@maxbla Have you seen #221 ? I closed it after ~6 months because there was apparently no interest in merging it, but maybe there is still something useful in there for you, if you want to revive the topic with a new PR, since it implements something very similar to what you propose (the |
There is interest. But I maintain dozens of projects, so it can take me a very long time to merge PRs and/or it's very easy for me to lose track of PRs. Editing comments to include status updates probably doesn't help, as was done in #221. I don't get emails when edits are made. |
No worries and I did not mean to criticize, of course. It's just a matter of my personal PR hygiene that I close unmerged PRs on my own after a while when I've also moved on to other things and no longer intend to keep them updated / mergeable. |
This commit tweaks the Arbitrary impls of number types (integers, floats) to use the full range with a small bias toward "problem" values. This is a change from prior behavior that would use the `size` parameter to control the range of integers. In retrospect, using the `size` parameter this way was probably misguided. Instead, it should only be used to control the sizes of data structures instead of also constraining numeric ranges. By constraining numeric ranges, we leave out a huge space of values that are never tested. Fixes #27, Fixes #119, Fixes #190, Fixes #233, Closes #240
I have a type which wraps an
i32
, and wrote anArbitrary
impl like so:When I actually output what it's running with, the values are only ranging from
100
to-100
, instead of 100 completely random numbers as I'd expect. Additionally,shrink
appears to be flawed on these types. My understanding was that quickcheck would test for known problematic values for a given type. Fori32
I'd expect that to at minimum be1
,0
,-1
,i32::MAX
andi32::MIN
, but when I add theshrink
like so:I just see the same range of -100 to 100. This caused a critical bug that occurs for any values less than
-2451545
to go unnoticed.The text was updated successfully, but these errors were encountered: