Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Make the lazyRangeAllowsMoreThanIntMaxValue test run fast
  • Loading branch information
BalmungSan committed Apr 30, 2024
commit b4eb90ac556cb34db6799ef596b0ef02e58d7be5
17 changes: 9 additions & 8 deletions test/junit/scala/collection/immutable/LazyListTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -447,14 +447,15 @@ class LazyListTest {

@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
}
assertEquals(totalElements, count)
// We use a reverse range to avoid computing a lot of elements.
val maxValue = Int.MaxValue.toLong
val lazyList = LazyList.range(
start = maxValue * 2L,
end = 0,
step = -1L
)
val nums = lazyList.take(10)
assert(nums.forall(_ > maxValue))
}
}

Expand Down