summaryrefslogtreecommitdiff
path: root/test/junit
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-02-03 21:59:54 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-02-03 21:59:54 +1000
commit953559988a698d6663ac983ee7d9944e05bd861d (patch)
treed2b12610d04c9a510e9d5c2b0242118521fa1a15 /test/junit
parent6ecb997fa8eb305bf547ec8a6106ba2fd777a594 (diff)
parentbf599bc72a1fff4aa812e6d8962b2cabe14725ab (diff)
downloadscala-953559988a698d6663ac983ee7d9944e05bd861d.tar.gz
scala-953559988a698d6663ac983ee7d9944e05bd861d.tar.bz2
scala-953559988a698d6663ac983ee7d9944e05bd861d.zip
Merge commit 'bf599bc' into merge/2.11.x-to-2.12.x-20160203
Conflicts: src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala src/compiler/scala/tools/nsc/transform/Constructors.scala src/compiler/scala/tools/nsc/typechecker/Contexts.scala src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala src/scaladoc/scala/tools/nsc/doc/html/resource/lib/jquery.layout.js
Diffstat (limited to 'test/junit')
-rw-r--r--test/junit/scala/collection/SearchingTest.scala48
-rw-r--r--test/junit/scala/collection/immutable/VectorTest.scala30
2 files changed, 78 insertions, 0 deletions
diff --git a/test/junit/scala/collection/SearchingTest.scala b/test/junit/scala/collection/SearchingTest.scala
new file mode 100644
index 0000000000..2f939d625e
--- /dev/null
+++ b/test/junit/scala/collection/SearchingTest.scala
@@ -0,0 +1,48 @@
+package scala.collection
+
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import org.junit.Assert._
+import org.junit.Test
+import scala.collection.Searching._
+
+@RunWith(classOf[JUnit4])
+class SearchingTest {
+
+ @Test
+ def doesLinearSearchOnLinearSeqs() {
+
+ class TestSeq[A](list: List[A]) extends SeqLike[A, TestSeq[A]] {
+ var elementsAccessed = Set.empty[Int]
+
+ protected[this] def newBuilder = ??? // not needed for this test
+ def seq = list
+ def iterator = list.iterator
+ def length = list.length
+ def apply(idx: Int) = { elementsAccessed += idx; list(idx) }
+ }
+
+ val coll = new TestSeq((0 to 6).toList)
+
+ assertEquals(Found(5), coll.search(5))
+ assertEquals(Set.empty, coll.elementsAccessed) // linear search should not access elements via apply()
+ }
+
+ @Test
+ def doesBinarySearchOnIndexedSeqs() {
+
+ class TestIndexedSeq[A](vec: Vector[A]) extends IndexedSeqLike[A, TestIndexedSeq[A]] {
+ var elementsAccessed = Set.empty[Int]
+
+ protected[this] def newBuilder = ??? // not needed for this test
+ def seq = vec
+ def length = vec.length
+ def apply(idx: Int) = { elementsAccessed += idx; vec(idx) }
+ }
+
+ val coll = new TestIndexedSeq((0 to 6).toVector)
+
+ assertEquals(Found(5), coll.search(5))
+ assertEquals(Set(3, 5), coll.elementsAccessed)
+ }
+}
diff --git a/test/junit/scala/collection/immutable/VectorTest.scala b/test/junit/scala/collection/immutable/VectorTest.scala
new file mode 100644
index 0000000000..69f74872d0
--- /dev/null
+++ b/test/junit/scala/collection/immutable/VectorTest.scala
@@ -0,0 +1,30 @@
+package scala.collection.immutable
+
+import org.junit.Assert._
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import org.junit.Test
+
+@RunWith(classOf[JUnit4])
+class VectorTest {
+
+ @Test
+ def hasCorrectDropAndTakeMethods() {
+ val v = Vector(0) ++ Vector(1 to 64: _*)
+
+ assertEquals(Vector(0, 1), v take 2)
+ assertEquals(Vector(63, 64), v takeRight 2)
+ assertEquals(Vector(2 to 64: _*), v drop 2)
+ assertEquals(Vector(0 to 62: _*), v dropRight 2)
+
+ assertEquals(v, v take Int.MaxValue)
+ assertEquals(v, v takeRight Int.MaxValue)
+ assertEquals(Vector.empty[Int], v drop Int.MaxValue)
+ assertEquals(Vector.empty[Int], v dropRight Int.MaxValue)
+
+ assertEquals(Vector.empty[Int], v take Int.MinValue)
+ assertEquals(Vector.empty[Int], v takeRight Int.MinValue)
+ assertEquals(v, v drop Int.MinValue)
+ assertEquals(v, v dropRight Int.MinValue)
+ }
+}