Comments (17)
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.
from quickcheck.
Maybe it's time to make a change like #99, but for numbers?
- With 1/4 probability, pick a number from [-100,100]
- With 3/4-1/25 probability, pick random bit pattern interpreted as a number
- With 3/100 probability, pick a power of two + [-3,3]
- With 1/100 probability, pick a number from some pre-selected set of tricky numbers that have more than one bug about and not already included in "1." or "3.". Some typical constants for CRC or prime numbers may appear there.
That could make "sane default" for multiple varied uses. Obviously one could override the distribution to task-specific.
from quickcheck.
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.
from quickcheck.
@sgrif I think the original idea here is that the size
method on quickcheck::Gen
would control the magnitude of the integers generated, but perhaps that is a misuse. With #116 merged, I think there is now good precedent for biasing towards known problematic values.
from quickcheck.
It is somewhat reversed #99: numbers being biased too much towards -100...100
.
I'm going to prepare a reformed number generation analogous to char (but simpler) which should cover entire range, yet preferring some particular numbers.
from quickcheck.
Experienced a problem with some tests: stratis-storage/stratisd@0f7838d, all u64 values were less than minimum required, so all testt were discarded.
from quickcheck.
With current behaviour that is expected @mulkieran and you simply need a wrapper type that defines the distribution of values that you need.
from quickcheck.
@bluss Can you give me an example?
from quickcheck.
if anyone who understand this problem can give me some help, I'ld appreciate it.
from quickcheck.
Something like this to make a wrapper type that puts a value inside using the regular Rand
impl (not Arbitrary
)
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())
}
}
from quickcheck.
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.
from quickcheck.
The Haskell implementation seems to first decide maximum bits the generated number has. Then generate a number within the range (-2 ^ max_bits, 2 ^ max_bits)
. Doing something similar is possible but doing it without regressing performance would be tricky.
Current workaround would be setting environment variable QUICKCHECK_GENERATOR_SIZE=18446744073709551615
on 64-bit platform. Not sure how feasible it is to change the default gen.size()
from 100 to usize::MAX
. It seems it does not hurt performance at least.
from quickcheck.
@BurntSushi I'd like to hear your thoughts about following propositions addressing this issue.
- Ensure that every valid value* for each integer type has some positive probability of being returned by
Arbitrary
- Completely ignore the
size
ofGen
(for integer types) - Have a greater chance to pick problematic values
- The most problematic values for any type are probably 0, MAX_VALUE and MIN_VALUE, but I could see -1 and 1 being included in this list along with all numbers at "bit transitions" i.e. 3,4,7,8,15,16
- Use a uniform distribution (besides problematic values)
- Another candidate distribution is the Geometric/Exponential distribution
*valid values for an integer type T
means every value in
T::min_value()..=T::max_value()
from quickcheck.
@maxbla Thanks for writing that out! I think that all seems pretty reasonable to me.
from quickcheck.
@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 size
parameter is not ignored but acts as a weighted bias towards a preferred range).
from quickcheck.
I closed it after ~6 months because there was apparently no interest in merging it
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.
from quickcheck.
@romanb yep, I saw #221, and thanks, it was helpful in creating #240.
from quickcheck.
Related Issues (20)
- Cannot use Rng methods on `Gen` when implementing `Arbitrary` HOT 5
- Identity checking HOT 3
- Stack overflow in quickcheck case shrinking HOT 3
- example case sort TEST FAILED HOT 1
- QuickChecking Const Generic Code HOT 5
- Implement Arbitrary for AsMut<[T: Arbitrary]> HOT 2
- Infinite Repetition/Never Ending Test with `f32` and `f64`. HOT 17
- Q: Idiomatic way to specify the length of an arbitrary vector HOT 7
- <newbie> How to generate a number within a range HOT 2
- Negating an integer leads to stack overflow HOT 2
- upgrade notes would be nice. HOT 1
- debug_reprs taking up 41% of test runtime HOT 2
- warning: panic message is not a string literal HOT 1
- Rng Size for Vec Arbitrary cannot be 0
- Impl Clone for Gen
- Implement something like choose_weighted for `Gen`
- Is this still maintained? HOT 1
- Is quickcheck still maintained? HOT 1
- How to combine quickcheck 1+ with fake? HOT 3
- Durations's Arbitrary instance is dependant on Gen's size HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quickcheck.