rust-random / book

The Rust Rand Book
Other
52 stars 20 forks source link

Add a new page that explains testing functions that use random generator #64

Closed Fethbita closed 3 weeks ago

Fethbita commented 3 weeks ago

Give an example showing how to make a MockRng struct and use it instead, providing a default RNG as well as recommended in https://github.com/rust-random/rand/issues/1319.

Feel free to change the explanation or edit the code or leave feedback.

Fethbita commented 3 weeks ago

One problem with this solution is that if there are multiple tests that require different values, it won't work. The Default trait can be implemented only a single time.

Fethbita commented 3 weeks ago

Made the requested changes. Thanks for the comments.