-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
generated Generic Functions are not pure #126
Comments
@Danny02 Shouldn't happen. Can you give an example? |
@jlink I created a minimal failing example for you (it happens with a custom arbitrary provider) |
Copying your example:
How are instances of |
|
the more minimal example
fails too. without any custom generators. Both example are working if the generic types are replaced by concrete. |
As I see it the behaviour is correct (and seems to have been the same in version 1.2.7 and before). Let me explain: Since Returning the same instance in repeated calls seems wrong to me because most functions (e.g. factories) do not work that way. This has also been discussed here: #73 So what can you do? I suggest you restrict the type variable in some way to make sure only types with reasonable equality behaviour are considered, e.g.:
Alternatively you could create a domain that only provides types that you consider useful for purity testing and use this domain in those tests. A possible new feature would be to have is some kind to filter out types of type variables, e.g. through an annotation like I'm closing this issue. Feel free to reopen it if my reasoning is flawed, which is the case often enough. |
Hi thx for the explaination of this behavior, but I think there is something different going on in my initial problem (I encountered in my project).
In this example I do not use Do you see anything wrong with my ArbitraryProvider implementation? |
I can replicate your problem. It seems unrelated to the behaviour described above. I'll have a closer look at it. |
It's a really tricky bug. Thanks for catching it! It (probably) has to do with Java's Arbitrary<Validation<?, ?>> create(Arbitrary<?> fail, Arbitrary<?> success) {
return Arbitraries.oneOf(
success.map(Validation::valid),
fail.map(Validation::invalid)
);
} It makes clear what the original Arbitrary<Validation<?, ?>> create(Arbitrary<?> fail, Arbitrary<?> success) {
return Arbitraries.frequencyOf(
Tuple.of(4, success.map(Validation::valid)),
Tuple.of(1, fail.map(Validation::invalid))
);
} which will give you a 20% probability for invalids. |
yes this is a mutch more clear implementation^^ |
I also fixed the original problem. Available in 1.3.7-SNAPSHOT |
Testing Problem
While switching from 1.2.7 to 1.3.6 I encountered the following regression.
a property for a generic value of type T and and a second value of type Function<T, String> generates functions which are not pure. Some of the functions called with the first value return different values on each call.
The text was updated successfully, but these errors were encountered: