Re:Property-Based Testing for the People
by eslaught on Monday January 06, 2025 @11:19PM
(#42619185)
I would pick the number of non-zeros first, assert that it's non-zero, then continue filling in the values themselves. And probably not with a uniform distribution.
Any algorithm that cares about the number of non-zeros could have non-trivial interactions with their arrangement and count, so picking something that generates non-trivial sparsity (and doesn't just make the array look like white noise) is going to have the best chance of exposing interesting behavior. The tricky part is thinking through how to generate "interesting" patterns, which admittedly I haven't put enough thought into.
Re:Property-Based Testing for the People
by dllthomas on Monday January 06, 2025 @11:36PM
(#42619279)
Ah, yeah, generating for property testing probably doesn't want a uniform distribution. What patterns are interesting will surely depend on what we're doing with the array.
Re:Property-Based Testing for the People
by jgalt212 on Tuesday January 07, 2025 @07:17AM
(#42621639)
Indeed, the world is not IID. As such, test cases should not be a uniformly distributed sample of some mathematical distribution.
My initial impulse is to pick a random cell which must not be zero, generate a random number for each other cell and a random non-zerp number for that one. I'm not immediately decided on whether it's uniformly distributed.