proptest: `sample()` and `select()` functions are missing
My use case is a graph, where all nodes are randomly created, and then I want to select a subset for each node to connect to when I create the actual graph.
However, there doesn’t seem to be either a sample()
or select()
api with which to do this.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 52
Commits related to this issue
- partial solution to #13 - added collection::{CollectionStrategy, subsequence} — committed to Centril/proptest by Centril 7 years ago
Done initial work on
subsequence
- todo: tests and moreCollectionStrategy
impls. Work in #8 .@AltSysrq That shrinking logic seems like a better idea with a better notion of chaos (locality / delta).
@vitiral
bounds
refers to (min/max) - anamount
is not aRange<usize>
- but what a parameter is named isn’t that important. What is important is giving a clear documentation about the behaviors of the method. I think fail-fast behavior in response to what is clearly a programmer-error is appropriate - the standard library does use panics for that in certain places - it is even more appropriate for a testing lib.To be clear,
subsequence
effectively would first randomizeamount in [bounds.start, bounds.end]
and then usesample
with that.Now I know what you want =)
Doing this as a trait is probably reasonable.
Is the following valid?
What are the semantics of (un)shrinking? A proposal:
ValueTree
should be generated with an initial sub-Vec
.simplify()
theValueTree
should remove one tail element from the last-returned sub-Vec
if it hasn’t reached the minimum length. This removed element is added to anotherVec
stored in theValueTree
complicate()
, the last removed element should be re-added.The type is thus:
A version on this is to alternate between removing the first / last element. It depends on if you want to bias towards the first element being the simplest, or if you want the middle element to be the simplest (in which case you alternate).
I think
.select
is unnecessary since we already haveUnion
, so you can do:Tho for performance a more specialized solution may be right.