-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix LazyList.range
[ci: last-only]
#10767
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
base: 2.13.x
Are you sure you want to change the base?
Changes from 6 commits
6de2bf8
91088b5
bd3db0d
f7745a4
2028dae
fbc2623
1ac4f64
b4eb90a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -444,8 +444,20 @@ class LazyListTest { | |
LazyList(1).lazyAppendedAll({ count += 1; Seq(2)}).toList | ||
assertEquals(1, count) | ||
} | ||
|
||
@Test | ||
def lazyRangeAllowsMoreThanIntMaxValue(): Unit = { | ||
val totalElements: Long = Int.MaxValue.toLong + 2L | ||
val count: Long = | ||
LazyList | ||
.range(start = 0L, end = totalElements) | ||
.foldLeft(0L) { case (acc, _) => | ||
acc + 1L | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. even with inlining turned on, it's a lot to ask of a unit test. Maybe it's sufficient to test construction and head. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I was wondering the same. So not sure if there is a smart way to test this without it being a CPU trap. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a reverse |
||
assertEquals(totalElements, count) | ||
} | ||
} | ||
|
||
object LazyListTest { | ||
var serializationForceCount = 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.
Uhm, wait, this does not allow reversed ranges, does it? Like
LazyList.range(start = 100, end = 0, step = -2)
I guess rather than check for
lt
we have to check for!ev.equiv(start, end)
?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.
Also, this made me think. This could be a good way to test this without a CPU trap. We just request the reversed range and then we can indeed ask for the
head
and check it is bigger thanInt.MaxValue
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.
good point, the check is incorrect, hmm. probably need to check the sign or something as well. I'll have another look shortly
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.
my thought is to check the sign of
step
in the 3 parameter overload ofrange
, and then pass it as aBoolean
parameter (probably namedpositiveStep
) torangeImpl
, thus checking the condition only once rather than for each elementUh oh!
There was an error while loading. Please reload this page.
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 just pushed an implementation that allows for reverse
ranges
.Let me know what you think about it.