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

Commit

Permalink
Merge pull request #370 from julienrf/listbuffer-fixes
Browse files Browse the repository at this point in the history
Fix clear operation in ListBuffer
  • Loading branch information
julienrf authored Jan 29, 2018
2 parents 80bebef + c0c0b4d commit 172ccb2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class ListBuffer[A]

def clear(): Unit = {
first = Nil
len = 0
last0 = null
aliased = false
}

def addOne(elem: A): this.type = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package strawman.collection.mutable

import strawman.collection.immutable.Nil

import org.junit.{Assert, Test}
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@RunWith(classOf[JUnit4])
class ListBufferTest {

@Test
def hasCorrectClear(): Unit = {
val b = ListBuffer.empty[String]
b += "a"
Assert.assertTrue(b.sameElements("a" :: Nil))
b.clear()
Assert.assertEquals(ListBuffer.empty[String], b)
b += "b"
Assert.assertTrue(b.sameElements("b" :: Nil))

val b2 = ListBuffer.empty[String]
b2 += "a"
val _ = b2.toList
b2.clear()
b2 += "b"
Assert.assertTrue(b2.sameElements("b" :: Nil))
}

}

0 comments on commit 172ccb2

Please sign in to comment.