-
Notifications
You must be signed in to change notification settings - Fork 660
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 property testing extensions for custom generators #506
Conversation
…ertyContexts with homotype parameters
The |
Sorry for the long time to review this. I don't think that adding that Maybe there's another way to do this? |
I agree with @Kerooker . This is a breaking change that trades one set of time saving sugar for another. You save some code in your examples, but in other places have to add |
Could use |
Maybe we can provide extensions for Gen themselves?
And so on for all the extensions. We would kill two birds with one stone, because this would also be a good addition to current Gens, not only custom ones. What do you guys think? |
Very nice. I think that could work well, but do you still have the same issue with the overloads? Need to test that. |
Let us fiddle with this. I'll try something |
This should really be addressed at the language level. Kotlin should automatically choose lambda expressions with a single argument over multiple arguments for the implicit case. You should not need to specify an explicit lambda signature in order to use |
Yes it should be, but we can't change Kotlin :) |
Even if you could fix Kotlin, you might still want to support KotlinTest users on previous language versions. Maybe it would be less disruptive if you were to put a hold on this PR until a major version update, or some other breaking API change and ship them together? I'm not sure if there is a good way to support universal quantification extensions for property testing using the simplified edit: You could change the name for higher arities, although maybe that's not quite as satisfying a solution. |
I don't want to force users to have to declare it as the parameter because that's not intuitive. Despite the fact that the language forces this, I think users would be surprised as to why their code was not compiling. I think @Kerooker's proposal is the best so far, overload the Generator itself, and don't include the unary versions there. Backwards compatible, and just as easy as the alternative. |
As suggested by @Kerooker, I added the higher arity versions of |
I believe that this is on point on what I had in mind! Good one! However some work should still be done.
|
A test with iterations != 1000 would be good to cover the iterations parameter, then I think we're good |
Thank you for your feedback. I have added an |
IntelliJ IDEA seems to run very slowly on this codebase. Is it just me or you have any suggestions to make navigation and compilation more responsive? |
There's a lot of code. You have to let it build at least once, then it will get a little bit smoother. |
…ertyContexts with homotype parameters
Ok. One more thing As we're adding these extensions, why not add one with arity = 1?
|
Not sure, @sksamuel?
|
I suppose it's because the JVM would clash as the signature would be the same, but this isn't supposed to be called from Java anyway, so we can change the name. But I mean, if the user wants to use |
I would skip the unary version, but it’s your call. Having two methods which do the same thing may lead to some confusion, and you may want to avoid the scenario where the user assumes (incorrectly) that |
Having two ways to do something is not ideal, as @breandan says.
Because it will pick up the default double generator.
Maybe more elegant to do
? I don't have a strong opinion either way. |
I think that allowing unary gens to be used with the extension is also good. |
@breandan If you don't, I can do it :) |
I think this is good to merge now. |
Great contribution @breandan |
I wanted to write:
But instead, I had to write:
This seemed a bit repetitive, so I added some extra extension methods to support the first notation.
Been using KotlinTest for a while and enjoying it so far! Thanks for this awesome project.