-
Couldn't load subscription status.
- Fork 1.4k
ZIO Test: Add generators for time datatypes #2173
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
Conversation
| /** | ||
| * A generator of ZIO duration values. Shrinks toward Duration.Zero. | ||
| */ | ||
| final def anyDuration: Gen[Random, Duration] = Gen.long(0L, Long.MaxValue).map(Duration.Finite(_)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyFiniteDuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. I've updated the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Just a few minor comments. Do you want to add any more generators? We could definitely do generators for other date / time classes if you had interest, but also fine to merge with what we have here after these changes.
| /** | ||
| * A generator of ZIO duration values inside the specified range: [min, max]. | ||
| */ | ||
| final def duration(min: Duration, max: Duration): Gen[Random, Duration] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finiteDuration? Should we add a generator of infinite values (it would just be a constant generator) and possibly a generator of duration values that produces both? Not sure what ratio of finite to infinite values would make sense.
| final def anyFiniteDuration: Gen[Random, Duration] = Gen.long(0L, Long.MaxValue).map(Duration.Finite(_)) | ||
|
|
||
| /** | ||
| * A generator java.time.Instant values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"generator of" instead of "generator". I would put the class names like java.time.Instant in back ticks. Also briefly state what the generator shrinks towards.
| object TimeVariantsSpec extends AsyncBaseSpec { | ||
|
|
||
| val run: List[Async[(Boolean, String)]] = List( | ||
| label(anyFiniteDurationShrinksToZero, "anyFiniteDuration shrinks to zero"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add properties about what any of the other generators shrink to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your feedback! I'm still working on improvements...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. Just reach out whenever you're ready for another review.
|
Hi @adamgfraser, generators for (finite) Duration, Instant, LocalDatetime and OffsetDateTime are ready for another review now. I would not add more datatypes in this PR because one can derive many similar types from the existing ones in a trivial way (i.e. LocalDateTime.toLocalTime). However I would like to add anyDuration, but therefor we have to combine a constant generator that emits Infinity with the existing anyFiniteDuration generator reasonably and it's unclear to me how to do that. Do you have an clue about this? Otherwise let`s add that later in another PR... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Congratulations on your first contribution!
|
@dieproht To combine a generator of finite values with a generator of infinite values we could either do something like |
* Add generators for time datatypes * renamed anyDuration anyFiniteDuration * improved generators and tests
|
Thank you @adamgfraser for supporting this! |
This is an extension of Gen implementing generators for basic time datatypes: ZIO duration, Instant, LocalDateTime and OffsetDateTime. The implementation is done in the way like diskussed with @adamgfraser at Berlin hackathon.