Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package cats.effect.internals
*
* INTERNAL API.
*/
final private[internals] class ArrayStack[A] private (
final private[internals] class ArrayStack[A <: AnyRef] private (
initialArray: Array[AnyRef],
chunkSize: Int,
initialIndex: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ import org.scalatest.funsuite.AnyFunSuite

class ArrayStackTests extends AnyFunSuite with Matchers with TestUtils {
test("push and pop 8 items") {
val stack = new ArrayStack[Int]()
val stack = new ArrayStack[String]()
var times = 0

while (times < 10) {
assert(stack.isEmpty, "stack.isEmpty")
for (i <- 0 until 8) stack.push(i)
for (i <- 0 until 8) stack.push(i.toString)

var list = List.empty[Int]
var list = List.empty[String]
while (!stack.isEmpty) {
assert(!stack.isEmpty, "!stack.isEmpty")
list = stack.pop() :: list
}

list shouldBe (0 until 8).toList
list shouldBe (0 until 8).map(_.toString).toList
stack.pop().asInstanceOf[AnyRef] shouldBe null
stack.isEmpty shouldBe true

Expand All @@ -43,20 +43,20 @@ class ArrayStackTests extends AnyFunSuite with Matchers with TestUtils {
}

test("push and pop 100 items") {
val stack = new ArrayStack[Int]()
val stack = new ArrayStack[String]()
var times = 0

while (times < 10) {
assert(stack.isEmpty, "stack.isEmpty")
for (i <- 0 until 100) stack.push(i)
for (i <- 0 until 100) stack.push(i.toString)

var list = List.empty[Int]
var list = List.empty[String]
while (!stack.isEmpty) {
assert(!stack.isEmpty, "!stack.isEmpty")
list = stack.pop() :: list
}

list shouldBe (0 until 100).toList
list shouldBe (0 until 100).map(_.toString).toList
stack.pop().asInstanceOf[AnyRef] shouldBe null
stack.isEmpty shouldBe true

Expand All @@ -65,30 +65,30 @@ class ArrayStackTests extends AnyFunSuite with Matchers with TestUtils {
}

test("pushAll(stack)") {
val stack = new ArrayStack[Int]()
val stack2 = new ArrayStack[Int]()
val stack = new ArrayStack[String]()
val stack2 = new ArrayStack[String]()

for (i <- 0 until 100) stack2.push(i)
for (i <- 0 until 100) stack2.push(i.toString)
stack.pushAll(stack2)

var list = List.empty[Int]
var list = List.empty[String]
while (!stack.isEmpty) {
assert(!stack.isEmpty)
list = stack.pop() :: list
}

list shouldBe (0 until 100).toList.reverse
list shouldBe (0 until 100).map(_.toString).toList.reverse
stack.pop().asInstanceOf[AnyRef] shouldBe null
stack.isEmpty shouldBe true
stack2.isEmpty shouldBe false
}

test("pushAll(iterable)") {
val stack = new ArrayStack[Int]()
val expected = (0 until 100).toList
val stack = new ArrayStack[String]()
val expected = (0 until 100).map(_.toString).toList
stack.pushAll(expected)

var list = List.empty[Int]
var list = List.empty[String]
while (!stack.isEmpty) {
assert(!stack.isEmpty)
list = stack.pop() :: list
Expand All @@ -100,8 +100,8 @@ class ArrayStackTests extends AnyFunSuite with Matchers with TestUtils {
}

test("iterator") {
val stack = new ArrayStack[Int]()
val expected = (0 until 100).toList
val stack = new ArrayStack[String]()
val expected = (0 until 100).map(_.toString).toList
for (i <- expected) stack.push(i)
stack.iteratorReversed.toList shouldBe expected.reverse
}
Expand Down