-
Notifications
You must be signed in to change notification settings - Fork 323
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
Review Range and Interval, resolve infinite loop issue #3408
Review Range and Interval, resolve infinite loop issue #3408
Conversation
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Interval.enso
Outdated
Show resolved
Hide resolved
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Interval.enso
Outdated
Show resolved
Hide resolved
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Number/Extensions.enso
Outdated
Show resolved
Hide resolved
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.
Nothing major but a few little tweaks.
@@ -27,7 +64,9 @@ type Range | |||
|
|||
0.up_to 100 . is_empty | |||
is_empty : Boolean | |||
is_empty = this.end <= this.start | |||
is_empty = if this.step > 0 then this.end <= this.start else |
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.
Interval.inclusive 0 0
means this will throw an error?
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.
Interval is not related to Range
...ntime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/ModNode.java
Show resolved
Hide resolved
|
||
Test.specify "should report errors if trying to set step to 0" <| | ||
0.up_to 0 . with_step 0 . should_fail_with Illegal_State_Error | ||
invalid_range = Range 0 0 0 |
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.
Maybe test Range 0 0 2
as well? Just to cover corner cases
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.
But this range is not invalid, it is just empty.
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.
A range is only invalid if its step is 0 - because the step should be a non-zero integer (so technically a range is also invalid if the step is decimal, but this is a typelevel check).
A range whose step exceeds end-start
is still valid, but will be empty if start=end
or contain just a single element [start]
.
1c7a199
to
6cc1faa
Compare
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.
LGTM. An extra test for with BigIntegers would be quite handy
TODO: shouldnt mod and % be separate operators like / and div are?
Co-authored-by: James Dunkerley <jdunkerley@users.noreply.github.com>
cfa9b49
to
80b771d
Compare
Pull Request Description
Implements: https://www.pivotaltracker.com/story/show/181652841
Important Notes
Checklist
Please include the following checklist in your PR:
./run dist
and./run watch
.