Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Commit 4091af0

Browse files
committed
Add back prependAll to buffer. Uncomment some ArrayDeque tests.
1 parent b15d7d4 commit 4091af0

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

collections/src/main/scala/strawman/collection/mutable/ArrayDeque.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ArrayDeque[A] protected (
8686
this
8787
}
8888

89-
/*override*/ def prependAll(elems: IterableOnce[A]): this.type = {
89+
override def prependAll(elems: IterableOnce[A]): this.type = {
9090
val it = elems.iterator()
9191
if (it.nonEmpty) {
9292
val n = length
@@ -133,7 +133,7 @@ class ArrayDeque[A] protected (
133133
val n = length
134134
if (idx == 0) {
135135
prepend(elem)
136-
} else if (idx == n - 1) {
136+
} else if (idx == n) {
137137
addOne(elem)
138138
} else {
139139
val finalLength = n + 1

collections/src/main/scala/strawman/collection/mutable/Buffer.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ trait Buffer[A]
2727
/** Alias for `prepend` */
2828
@`inline` final def +=: (elem: A): this.type = prepend(elem)
2929

30+
def prependAll(elems: IterableOnce[A]): this.type = { insertAll(0, elems); this }
31+
32+
/** Inserts a new element at a given index into this buffer.
33+
*
34+
* @param idx the index where the new elements is inserted.
35+
* @param elem the element to insert.
36+
* @throws IndexOutOfBoundsException if the index `idx` is not in the valid range
37+
* `0 <= idx <= length`.
38+
*/
3039
@throws[IndexOutOfBoundsException]
3140
def insert(idx: Int, elem: A): Unit
3241

test/junit/src/test/scala/strawman/collection/mutable/ArrayDequeTest.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ class ArrayDequeTest {
2323
apply(_.prepend(6).prepend(7).prepend(8))
2424
apply(_.trimStart(2))
2525
apply(_.trimEnd(3))
26+
apply(_.insert(2, -3))
2627
apply(_.insertAll(0, collection.Seq(9, 10, 11)))
2728
apply(_.insertAll(1, collection.Seq(12, 13)))
2829
apply(_.insertAll(0, collection.Seq(23, 24)))
2930
apply(_ ++= Seq(25, 26))
3031
apply(_.insertAll(3, collection.IndexedSeq(18, 33)))
3132
apply(_.remove(2))
32-
// apply(_.prependAll(Seq(14, 15, 16, 17)))
33+
apply(_.prependAll(collection.Seq(14, 15, 16, 17)))
3334
apply(_.remove(1, 5))
34-
// apply(_.prependAll(Seq.tabulate(100)(identity)))
35+
apply(_.prependAll(Seq.tabulate(100)(identity)))
3536
apply(b => b.insertAll(b.length - 5, collection.Seq.tabulate(10)(identity)))
3637
buffer.trimToSize()
3738
apply(_.addAll(collection.Seq.tabulate(100)(identity)))

0 commit comments

Comments
 (0)