Skip to content
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

Distribute the sizes of the generated elements in Gen.array2DOf. #495

Closed
wants to merge 1 commit into from
Closed

Distribute the sizes of the generated elements in Gen.array2DOf. #495

wants to merge 1 commit into from

Conversation

Kharacternyk
Copy link
Contributor

This PR makes the behaviors of array2DOf and arrayOf consistent.

Maybe there should be some wrapper types to allow users to generate lists and arrays the old way? (related: #444)

This commit makes the behaviors of array2DOf and arrayOf consistent.
@kurtschelfthout
Copy link
Member

Hm, yes I hadn't thought of using wrapper types. Or maybe just some extra Arbitrary.Default methods would be fine too.

@kurtschelfthout
Copy link
Member

Anyway I'm not convinced we should do this for 2D arrays. 2D arrays do not usually contain nested structures.

@Kharacternyk
Copy link
Contributor Author

There are two ways of representing a multi-dimensional array in .NET: nested arrays and "real" 2,3...d arrays. It is an implementation detail, logically they are the same (I mean they equally represent matrixes of fixed width and height. Nested arrays can be used for some other things though).

IMHO FsCheck should distribute a size the same way in both of these cases.

@kurtschelfthout
Copy link
Member

I don't agree it's an implementation detail. 2D arrays are mostly used to represent matrices, and mostly contain primitive types (floats etc). I'd never represent a matrix as a nested array.

The distribution of the size is actually a pretty complicated question. I'm not sure absolute consistency is the answer here. Size is most importantly a mechanism to control the time it takes to generate complex values. For recursive values size bounds the number of recursions. For primitive types (and also complex types) on the other hand it's just a heuristic to make "smaller" test failures happen "sooner". But the latter becomes a lot less important when shrinking is in play.

The trade-off here is that smaller values arguably means less test coverage.

The 1D size distribution mechanism was changed from giving each element of a list n-1 size to making the sum of the sizes add up to n, because 1D data structures frequently contain complex values, and more importantly, can contain nested 1D data structures (e.g. list<array<T>>). In those cases it becomes important to distribute the size in such a way that individual elements get a much lower size than size-1.

But my sense is that for 2D arrays it's much less the case that they contain complex elements, and I can't remember ever seeing a thing like array[,]<list<T>> or something like that. So that would indicate that for 2D arrays we're fine to assign size-1 to each element of the 2D array, and thereby increase test coverage somewhat.

Does that make sense?

@Kharacternyk
Copy link
Contributor Author

I understand your point. Yeah, it makes sense. I'm going to add the shortened version of all of the above to xml docs in #494.

@Kharacternyk Kharacternyk deleted the fix-multi-dim-arrays-gens branch April 10, 2019 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants