std.random: No equality checks for doc example unittests#5762
std.random: No equality checks for doc example unittests#5762dlang-bot merged 1 commit intodlang:stablefrom
Conversation
|
Thanks for your pull request, @kinke! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Some tips to help speed things up:
Bear in mind that large or tricky changes may require multiple rounds of review and revision. Please see CONTRIBUTING.md for more information. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
|
Perhaps we should make the assertion conditional on the size of On the other hand I'm not sure why the documentation example assumes that
@WebDrake please advice. |
|
Even leaving the |
|
It does indeed seem dodgy to assume that TBH I think the problems of this unittest come out of a confused purpose: it's really a module-level documentation example, so there's no need for it to check these result values at all. Checks on the results of deterministically seeded RNGs can be (and are) made in the more in-depth checks of those RNGs themselves. I'd suggest just cutting all the equality checks on results in this unittest block. If not I guess |
PetarKirov
left a comment
There was a problem hiding this comment.
Testing exact equality of floating-point values in the documentation of this module is not a good idea. It can be either non-portable (wrong on some platforms) or correct, but requiring too much effort than necessary for something that ought to be simple in which case distracting the users from the main objective of the example.
| assert(r == 79.65429843861011285); | ||
| import std.math : approxEqual; | ||
| assert(approxEqual(r, 79.65429843861011285)); | ||
|
|
There was a problem hiding this comment.
Given @WebDrake advice, I think it's better to simply remove the equality comparisons and instead assert that the numbers are in the expected intervals.
There was a problem hiding this comment.
@ZombineDev I take it you're talking here only about the floating-point number? The integer variates generated elsewhere in the unittest should be exactly equal, assuming that Random is reliably Mt19937.
There was a problem hiding this comment.
Yes, I mean the integer cases too, since I don't think knowledge of the Random's implementation should be assumed for the readers of the first example in the documentation. Testing the exact values should be done only when the exact random engine is explicitly specified, in addition to its seed, IMO.
There was a problem hiding this comment.
Oh, so you mean in this case you'd check that the resulting number is >= 0 and < 100, and for the uniform(0, 15, rnd) call you'd check that it's >= 0 and < 15?
That sounds reasonable, yes. Note that for the uniform!uint case this won't really work since the range of possible values covers the entire range of possible values for that type; but you don't really have to validate that result at all anyway.
They depend on the `Random` alias as well as the `real` precision.
No description provided.