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

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

Merged
merged 3 commits into from
Oct 7, 2024

Conversation

Fethbita
Copy link
Contributor

@Fethbita Fethbita commented Oct 4, 2024

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

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

Give an example showing how to make a MockRng struct and use it instead,
providing a default RNG as well
@Fethbita
Copy link
Contributor Author

Fethbita commented Oct 4, 2024

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 added a commit to Fethbita/emrtd that referenced this pull request Oct 5, 2024
The problem with this approach is that, different test functions can't
use different states of the Rng. Also since the returned values are
hardcoded in the MockRng, they are far away from the tests, should
find another approach to be able to set the values Rng must return in
the test functions themselves
Copy link
Member

@dhardy dhardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution

src/guide-test-fn-rng.md Outdated Show resolved Hide resolved
src/guide-test-fn-rng.md Outdated Show resolved Hide resolved
src/guide-test-fn-rng.md Outdated Show resolved Hide resolved
src/guide-test-fn-rng.md Outdated Show resolved Hide resolved
src/guide-test-fn-rng.md Outdated Show resolved Hide resolved
@Fethbita
Copy link
Contributor Author

Fethbita commented Oct 7, 2024

Made the requested changes. Thanks for the comments.

@dhardy dhardy merged commit bb54b73 into rust-random:master Oct 7, 2024
1 check passed
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