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

What are the consequences of an impure LazyJust? #533

Open
justinlovinger opened this issue Nov 20, 2024 · 0 comments
Open

What are the consequences of an impure LazyJust? #533

justinlovinger opened this issue Nov 20, 2024 · 0 comments

Comments

@justinlovinger
Copy link

I have a use-case where I need to generate unique identifiers as part of an implementation of Arbitrary. For example, given fn test_foo(foo_one: Foo, foo_two: Foo), foo_one and foo_two must have different identifiers. I am currently using LazyJust::new(|| Uuid::new_v4().to_string()) to ensure uniqueness. I cannot use Just because Proptest will clone the "unique" identifier, thereby making it non-unique. I cannot use standard Proptest generators because Proptest could generate non-unique values or shrink values into being non-unique. The documentation for LazyJust states "It is important that the function used be pure.". My current use of LazyJust is explicitly not pure, but I cannot find a better way to create a unique identifier for an arbitrary value of a type.

So, what are the consequences of using an impure function for LazyJust? Will shrinking still work, with the understanding that identifiers changing is acceptable? And, if Proptest works with an impure function for LazyJust, perhaps the documentation should be more specific?

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

No branches or pull requests

1 participant