-
Notifications
You must be signed in to change notification settings - Fork 30
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
Improve and extend DateTime/DateTimeOffset generation #252
Conversation
We should probably add tests, at least for the |
The bug is now fixed. I have experimented with both |
To be clear, the only outstanding thing here is the compilation error I mentioned if we should change the default range. I don't know what to do about that error, but it can also be done later (e.g. in another PR) or not at all (if you don't agree with the change). So feel free to review (and see if there is a simple fix to the compilation error when changing the range). |
Interesting. Is that issue happening on master or just in v0.8.3? |
The compilation error? On master (and 0.8.4). I discovered it while working on this PR, so I don't understand how 0.8.3 is relevant. |
Perhaps we're missing something in Numeric.fs(?) 🤔 Reminds me of #156. |
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.
👍 💯 I left a comment, but overall this looks great.
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.
👍
I have made the change now. Note:
|
I'd like to look into this before merging, if that's OK. |
Absolutely. |
Any chance to have a look at this so it can be merged? :) |
That compiler error you were getting is because of the @@ -53,11 +53,18 @@ let ``dateTime randomly generates value between max and min ticks`` () =
[<Fact>]
let ``dateTime shrinks to correct mid-value`` () =
let result =
property {
let! actual =
- Range.constantFrom (System.DateTime (2000, 1, 1)) System.DateTime.MinValue System.DateTime.MaxValue
+ Range.linearFrom
+ (System.DateTime (2000, 1, 1))
+ .Ticks
+ System.DateTime.MinValue
+ .Ticks
+ System.DateTime.MaxValue
+ .Ticks
+ |> Range.map System.DateTime
|> Gen.dateTime
System.DateTime.Now =! actual
}
|> Property.report
|> Report.render |
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! Looking good 👍 I've suggested a small change in the docs. We can merge after that.
Yes, but then you sidestep the whole generator and have effectively written your own generator. Furthermore, the same applies to |
I'm not sure I fully understand. I've added
|
My bad, I see you map the |
Co-authored-by: Nikos Baxevanis <nikos.baxevanis@gmail.com>
This PR consists of these changes, each in a separate commit:
DateTime
is decidedly not an instant in time;DateTimeOffset
is). This change was also done for consistency with the new functions added in later commits.Gen.dateTimeOffset
. It's a "primitive" that is non-trivial to generate (care must be taken to avoid overflows due to adding offsets around the min/max values) and should be in fsharp-hedgehogGen.dateTime
andGen.dateTimeOffset
, allowing users to specify their own date ranges (I have myself come across the need to limit the date ranges due to complicated time zone stuff some country did a hundred years ago, which is not interesting to account for in my domain)dateTime
anddateTimeOffset
in terms of their ranged variantsThere is one other change I'd like to make, but for some reason it won't compile: I'd like to change the default range of
dateTime
anddateTimeOffset
fromconstant
to eitherlinear
orexponential
. I don't see a reason why it should be size-independent. But when I tried to change it, I get compile errors: