-
Notifications
You must be signed in to change notification settings - Fork 308
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
Implement proptest's Arbitrary trait for Array #596
Comments
@jturner314 Hey, this looks both interesting and challenging for me at the same time, do you mind showing me some initial ideas? I currently reading |
I'm not really familiar with the internals of When I think about testing with
If I was to prioritize these, I'd focus on item (ii) of (1), item (iii) or (iv) of (2), and item (i) of (3). So, the parameter type could be (SizeRange, A::Parameters) if we only consider contiguous arrays with a limited number of elements. This would be great for an initial implementation. Or, we could do something more sophisticated like struct Parameters<A, D> {
/// Limits on the number of elements in the array.
len: SizeRange,
/// Limits on the axis lengths.
axis_lens: (D, D),
/// Restrict to only square arrays (default: `false`).
only_square: bool,
/// Restrictions on the memory layout of the array.
layout: Layout,
/// Parameters for the elements within the array.
elems: A::Parameters,
}
enum Layout {
/// Generate only contiguous, row-major arrays.
RowMajor,
/// Generate only contiguous, column-major arrays.
ColMajor,
/// Generate only contiguous arrays. (This is the default.)
Contiguous,
/// Generate arrays with arbitrary layout, but with bounded size in memory.
Arbitrary(SizeRange),
} I'd just focus on getting something simple working first (e.g. the |
This issue appears to be a bit dormant. I'll try and have a stab at it if no ones currently working on it? |
I've been working on this, and I've made a lot of progress. The hardest part to getting something working is the random generation of arbitrary shapes/layouts that are representative of all possible arrays within the constraints, while obtaining a reasonable distribution without expensive rejection sampling. I've mostly figured that part out. The other potentially difficult piece is a sophisticated simplification strategy, but I'm delaying that for later because it isn't critical for a MVP. I've been temporarily working on this in a branch of |
Property-based testing is a very powerful way to create robust tests, but it's currently somewhat difficult to use property-based testing with
Array
inputs becauseArray
doesn't implement theArbitrary
trait.It would be nice to implement the
Arbitrary
trait similar to the impl forVec
such that the shape and elements could be parameterized. We could also take the memory layout as a parameter (with choices row-major/column-major/contiguous/arbitrary) or just randomize it.The text was updated successfully, but these errors were encountered: