-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Size hint with delta is not negative
- Loading branch information
Showing
2 changed files
with
32 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
package scala.collection.mutable | ||
|
||
import org.junit.Test | ||
import org.junit.Assert.assertEquals | ||
|
||
class BuilderTest { | ||
class TestBuilder extends Builder[String, String] { | ||
val stuff = ListBuffer.empty[String] | ||
def clear() = stuff.clear() | ||
def result() = stuff.mkString("hello, world: ", ",", "") | ||
def addOne(s: String) = { stuff.addOne(s); this } | ||
var expectedSize = 16 | ||
override def sizeHint(size: Int) = expectedSize = size | ||
} | ||
|
||
@Test def `sizeHint is capped`: Unit = { | ||
val b = new TestBuilder | ||
val prototype = Nil | ||
b.sizeHint(prototype, delta = -1) | ||
assertEquals(0, b.expectedSize) | ||
b.addOne("tested!") | ||
assertEquals("hello, world: tested!", b.result()) | ||
} | ||
} |