diff options
Diffstat (limited to 'test/junit/scala/collection')
28 files changed, 1286 insertions, 86 deletions
diff --git a/test/junit/scala/collection/IteratorTest.scala b/test/junit/scala/collection/IteratorTest.scala index f18a4de4e9..1709e3c1bf 100644 --- a/test/junit/scala/collection/IteratorTest.scala +++ b/test/junit/scala/collection/IteratorTest.scala @@ -135,6 +135,20 @@ class IteratorTest { assertEquals(3, List(1, 2, 3, 4, 5).iterator.indexWhere { x: Int => x >= 4 }) assertEquals(-1, List(1, 2, 3, 4, 5).iterator.indexWhere { x: Int => x >= 16 }) } + @Test def indexOfFrom(): Unit = { + assertEquals(1, List(1, 2, 3, 4, 5).iterator.indexOf(2, 0)) + assertEquals(1, List(1, 2, 3, 4, 5).iterator.indexOf(2, 1)) + assertEquals(-1, List(1, 2, 3, 4, 5).iterator.indexOf(2, 2)) + assertEquals(4, List(1, 2, 3, 2, 1).iterator.indexOf(1, 1)) + assertEquals(1, List(1, 2, 3, 2, 1).iterator.indexOf(2, 1)) + } + @Test def indexWhereFrom(): Unit = { + assertEquals(1, List(1, 2, 3, 4, 5).iterator.indexWhere(_ == 2, 0)) + assertEquals(1, List(1, 2, 3, 4, 5).iterator.indexWhere(_ == 2, 1)) + assertEquals(-1, List(1, 2, 3, 4, 5).iterator.indexWhere(_ == 2, 2)) + assertEquals(4, List(1, 2, 3, 2, 1).iterator.indexWhere(_ < 2, 1)) + assertEquals(1, List(1, 2, 3, 2, 1).iterator.indexWhere(_ <= 2, 1)) + } // iterator-iterate-lazy.scala // was java.lang.UnsupportedOperationException: tail of empty list @Test def iterateIsSufficientlyLazy(): Unit = { @@ -154,6 +168,14 @@ class IteratorTest { results += (Stream from 1).toIterator.drop(10).toStream.drop(10).toIterator.next() assertSameElements(List(1,1,21), results) } + // SI-8552 + @Test def indexOfShouldWorkForTwoParams(): Unit = { + assertEquals(1, List(1, 2, 3).iterator.indexOf(2, 0)) + assertEquals(-1, List(5 -> 0).iterator.indexOf(5, 0)) + assertEquals(0, List(5 -> 0).iterator.indexOf((5, 0))) + assertEquals(-1, List(5 -> 0, 9 -> 2, 0 -> 3).iterator.indexOf(9, 2)) + assertEquals(1, List(5 -> 0, 9 -> 2, 0 -> 3).iterator.indexOf(9 -> 2)) + } // SI-9332 @Test def spanExhaustsLeadingIterator(): Unit = { def it = Iterator.iterate(0)(_ + 1).take(6) @@ -198,22 +220,32 @@ class IteratorTest { assertSameElements(exp, res) assertEquals(8, counter) // was 14 } - - // SI-9766 - @Test def exhaustedConcatIteratorConcat: Unit = { - def consume[A](i: Iterator[A]) = { - while(i.hasNext) i.next() - } - val joiniter = Iterator.empty ++ Seq(1, 2, 3) - assertTrue(joiniter.hasNext) - consume(joiniter) - val concatiter = joiniter ++ Seq(4, 5, 6) - assertTrue(concatiter.hasNext) - consume(concatiter) - assertFalse(concatiter.hasNext) - val concatFromEmpty = concatiter ++ Seq(7, 8, 9) - assertTrue(concatFromEmpty.hasNext) - consume(concatFromEmpty) - assertFalse(concatFromEmpty.hasNext) + // SI-9691 + @Test def bufferedHeadOptionReturnsValueWithHeadOrNone(): Unit = { + // Checks BufferedIterator returns Some(value) when there is a value + val validHeadOption = List(1,2,3).iterator.buffered.headOption + assertEquals(Some(1), validHeadOption) + // Checks BufferedIterator returns None when there is no value + val invalidHeadOption = List(1,2,3).iterator.drop(10).buffered.headOption + assertEquals(None: Option[Int], invalidHeadOption) + // Checks BufferedIterator returns Some(value) in the last position with a value + val validHeadOptionAtTail = List(1,2,3).iterator.drop(2).buffered.headOption + assertEquals(Some(3), validHeadOptionAtTail) + // Checks BufferedIterator returns None at the first position without a value + val invalidHeadOptionOnePastTail = List(1,2,3).iterator.drop(3).buffered.headOption + assertEquals(None, invalidHeadOptionOnePastTail) + // Checks BufferedIterator returns Some(null) if the next value is null. + val nullHandingList = List(null, "yellow").iterator.buffered.headOption + assertEquals(Some(null), nullHandingList) + // Checks that BufferedIterator is idempotent. That the head is not + // changed by its invocation, nor the headOption by the next call to head. + val it = List(1,2,3).iterator.buffered + val v1 = it.head + val v2 = it.headOption + val v3 = it.head + val v4 = it.headOption + assertEquals(v1, v3) + assertEquals(v2, v4) + assertEquals(Some(v1), v2) } } diff --git a/test/junit/scala/collection/LinearSeqOptimizedTest.scala b/test/junit/scala/collection/LinearSeqOptimizedTest.scala new file mode 100644 index 0000000000..b9c34ed17c --- /dev/null +++ b/test/junit/scala/collection/LinearSeqOptimizedTest.scala @@ -0,0 +1,19 @@ +package scala.collection + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Assert._ +import org.junit.Test + +@RunWith(classOf[JUnit4]) +class LinearSeqOptimizedTest { + + @Test def `SI-9936 indexWhere`(): Unit = { + assertEquals(2, "abcde".indexOf('c', -1)) + assertEquals(2, "abcde".indexOf('c', -2)) + assertEquals(2, "abcde".toList.indexOf('c', -1)) + assertEquals(2, "abcde".toList.indexOf('c', -2)) + assertEquals(2, "abcde".toList.indexWhere(_ == 'c', -1)) + assertEquals(2, "abcde".toList.indexWhere(_ == 'c', -2)) + } +} diff --git a/test/junit/scala/collection/NewBuilderTest.scala b/test/junit/scala/collection/NewBuilderTest.scala new file mode 100644 index 0000000000..fdc6af113d --- /dev/null +++ b/test/junit/scala/collection/NewBuilderTest.scala @@ -0,0 +1,184 @@ +package scala.collection + +import scala.{collection => sc} +import scala.collection.{mutable => scm, immutable => sci, parallel => scp, concurrent => scc} +import scala.collection.parallel.{mutable => scpm, immutable => scpi} + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import scala.reflect.ClassTag +import org.junit.Assert._ + +/* Tests various maps by making sure they all agree on the same answers. */ +@RunWith(classOf[JUnit4]) +class NewBuilderTest { + + @Test + def mapPreservesCollectionType() { + def test[T: ClassTag](mapped: Any): Unit = { + val expected = reflect.classTag[T].runtimeClass + val isInstance = reflect.classTag[T].runtimeClass.isInstance(mapped) + assertTrue(s"$mapped (of class ${mapped.getClass} is not a in instance of ${expected}", isInstance) + } + + test[sc.GenTraversable[_] ]((sc.GenTraversable(1): sc.GenTraversable[Int]).map(x => x)) + test[sc.Traversable[_] ]((sc.Traversable(1): sc.GenTraversable[Int]).map(x => x)) + test[sc.GenIterable[_] ]((sc.GenIterable(1): sc.GenTraversable[Int]).map(x => x)) + test[sc.Iterable[_] ]((sc.Iterable(1): sc.GenTraversable[Int]).map(x => x)) + test[sc.GenSeq[_] ]((sc.GenSeq(1): sc.GenTraversable[Int]).map(x => x)) + test[sc.Seq[_] ]((sc.Seq(1): sc.GenTraversable[Int]).map(x => x)) + test[sc.LinearSeq[_] ]((sc.LinearSeq(1): sc.GenTraversable[Int]).map(x => x)) + test[sc.LinearSeq[_] ]((sc.LinearSeq(1): sc.Seq[Int] ).map(x => x)) + test[sc.IndexedSeq[_] ]((sc.IndexedSeq(1): sc.GenTraversable[Int]).map(x => x)) + test[sc.IndexedSeq[_] ]((sc.IndexedSeq(1): sc.Seq[Int] ).map(x => x)) + test[sc.GenSet[_] ]((sc.GenSet(1): sc.GenTraversable[Int]).map(x => x)) + test[sc.Set[_] ]((sc.Set(1): sc.GenTraversable[Int]).map(x => x)) + test[sc.GenMap[_, _] ]((sc.GenMap(1 -> 1): sc.GenMap[Int, Int] ).map(x => x)) + test[sc.Map[_, _] ]((sc.Map(1 -> 1): sc.GenMap[Int, Int] ).map(x => x)) + + test[scm.Traversable[_] ]((scm.Traversable(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.Iterable[_] ]((scm.Iterable(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.LinearSeq[_] ]((scm.LinearSeq(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.LinearSeq[_] ]((scm.LinearSeq(1): sc.Seq[Int] ).map(x => x)) + test[scm.MutableList[_] ]((scm.MutableList(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.MutableList[_] ]((scm.MutableList(1): sc.Seq[Int] ).map(x => x)) + test[scm.Queue[_] ]((scm.Queue(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.Queue[_] ]((scm.Queue(1): sc.Seq[Int] ).map(x => x)) + test[scm.DoubleLinkedList[_]]((scm.DoubleLinkedList(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.DoubleLinkedList[_]]((scm.DoubleLinkedList(1): sc.Seq[Int] ).map(x => x)) + test[scm.LinkedList[_] ]((scm.LinkedList(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.LinkedList[_] ]((scm.LinkedList(1): sc.Seq[Int] ).map(x => x)) + test[scm.ArrayStack[_] ]((scm.ArrayStack(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.ArrayStack[_] ]((scm.ArrayStack(1): sc.Seq[Int] ).map(x => x)) + test[scm.Stack[_] ]((scm.Stack(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.Stack[_] ]((scm.Stack(1): sc.Seq[Int] ).map(x => x)) + test[scm.ArraySeq[_] ]((scm.ArraySeq(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.ArraySeq[_] ]((scm.ArraySeq(1): sc.Seq[Int] ).map(x => x)) + + test[scm.Buffer[_] ]((scm.Buffer(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.Buffer[_] ]((scm.Buffer(1): sc.Seq[Int] ).map(x => x)) + test[scm.IndexedSeq[_] ]((scm.IndexedSeq(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.IndexedSeq[_] ]((scm.IndexedSeq(1): sc.Seq[Int] ).map(x => x)) + test[scm.ArrayBuffer[_] ]((scm.ArrayBuffer(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.ArrayBuffer[_] ]((scm.ArrayBuffer(1): sc.Seq[Int] ).map(x => x)) + test[scm.ListBuffer[_] ]((scm.ListBuffer(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.ListBuffer[_] ]((scm.ListBuffer(1): sc.Seq[Int] ).map(x => x)) + test[scm.Seq[_] ]((scm.Seq(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.Seq[_] ]((scm.Seq(1): sc.Seq[Int] ).map(x => x)) + test[scm.ResizableArray[_] ]((scm.ResizableArray(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.ResizableArray[_] ]((scm.ResizableArray(1): sc.Seq[Int] ).map(x => x)) + test[scm.Set[_] ]((scm.Set(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.Set[_] ]((scm.Set(1): sc.Set[Int] ).map(x => x)) + test[scm.HashSet[_] ]((scm.HashSet(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.HashSet[_] ]((scm.HashSet(1): sc.Set[Int] ).map(x => x)) + test[scm.LinkedHashSet[_] ]((scm.LinkedHashSet(1): sc.GenTraversable[Int]).map(x => x)) + test[scm.LinkedHashSet[_] ]((scm.LinkedHashSet(1): sc.Set[Int] ).map(x => x)) + + test[sci.Traversable[_] ]((sci.Traversable(1): sc.GenTraversable[Int]).map(x => x)) + test[sci.Iterable[_] ]((sci.Iterable(1): sc.GenTraversable[Int]).map(x => x)) + test[sci.LinearSeq[_] ]((sci.LinearSeq(1): sc.GenTraversable[Int]).map(x => x)) + test[sci.LinearSeq[_] ]((sci.LinearSeq(1): sc.Seq[Int] ).map(x => x)) + test[sci.List[_] ]((sci.List(1): sc.GenTraversable[Int]).map(x => x)) + test[sci.List[_] ]((sci.List(1): sc.Seq[Int] ).map(x => x)) + test[sci.Stream[_] ]((sci.Stream(1): sc.GenTraversable[Int]).map(x => x)) + test[sci.Stream[_] ]((sci.Stream(1): sc.Seq[Int] ).map(x => x)) + test[sci.Stack[_] ]((sci.Stack(1): sc.GenTraversable[Int]).map(x => x)) + test[sci.Stack[_] ]((sci.Stack(1): sc.Seq[Int] ).map(x => x)) + test[sci.Queue[_] ]((sci.Queue(1): sc.GenTraversable[Int]).map(x => x)) + test[sci.Queue[_] ]((sci.Queue(1): sc.Seq[Int] ).map(x => x)) + test[sci.IndexedSeq[_] ]((sci.IndexedSeq(1): sc.GenTraversable[Int]).map(x => x)) + test[sci.IndexedSeq[_] ]((sci.IndexedSeq(1): sc.Seq[Int] ).map(x => x)) + test[sci.Vector[_] ]((sci.Vector(1): sc.GenTraversable[Int]).map(x => x)) + test[sci.Vector[_] ]((sci.Vector(1): sc.Seq[Int] ).map(x => x)) + test[sci.Seq[_] ]((sci.Seq(1): sc.GenTraversable[Int]).map(x => x)) + test[sci.Seq[_] ]((sci.Seq(1): sc.Seq[Int] ).map(x => x)) + test[sci.Set[_] ]((sci.Set(1): sc.GenTraversable[Int]).map(x => x)) + test[sci.Set[_] ]((sci.Set(1): sc.Set[Int] ).map(x => x)) + test[sci.ListSet[_] ]((sci.ListSet(1): sc.GenTraversable[Int]).map(x => x)) + test[sci.ListSet[_] ]((sci.ListSet(1): sc.Set[Int] ).map(x => x)) + test[sci.HashSet[_] ]((sci.HashSet(1): sc.GenTraversable[Int]).map(x => x)) + test[sci.HashSet[_] ]((sci.HashSet(1): sc.Set[Int] ).map(x => x)) + + test[scp.ParIterable[_] ]((scp.ParIterable(1): sc.GenTraversable[Int]).map(x => x)) + test[scp.ParSeq[_] ]((scp.ParSeq(1): sc.GenTraversable[Int]).map(x => x)) + test[scp.ParSeq[_] ]((scp.ParSeq(1): sc.GenSeq[Int] ).map(x => x)) + test[scp.ParSet[_] ]((scp.ParSet(1): sc.GenTraversable[Int]).map(x => x)) + test[scp.ParSet[_] ]((scp.ParSet(1): sc.GenSet[Int] ).map(x => x)) + + test[scpm.ParIterable[_] ]((scpm.ParIterable(1): sc.GenTraversable[Int]).map(x => x)) + test[scpm.ParSeq[_] ]((scpm.ParSeq(1): sc.GenTraversable[Int]).map(x => x)) + test[scpm.ParSeq[_] ]((scpm.ParSeq(1): sc.GenSeq[Int] ).map(x => x)) + test[scpm.ParArray[_] ]((scpm.ParArray(1): sc.GenTraversable[Int]).map(x => x)) + test[scpm.ParArray[_] ]((scpm.ParArray(1): sc.GenSeq[Int] ).map(x => x)) + test[scpm.ParSet[_] ]((scpm.ParSet(1): sc.GenTraversable[Int]).map(x => x)) + test[scpm.ParSet[_] ]((scpm.ParSet(1): sc.GenSet[Int] ).map(x => x)) + test[scpm.ParHashSet[_] ]((scpm.ParHashSet(1): sc.GenTraversable[Int]).map(x => x)) + test[scpm.ParHashSet[_] ]((scpm.ParHashSet(1): sc.GenSet[Int] ).map(x => x)) + + test[scpi.ParIterable[_] ]((scpi.ParIterable(1): sc.GenTraversable[Int]).map(x => x)) + test[scpi.ParSeq[_] ]((scpi.ParSeq(1): sc.GenTraversable[Int]).map(x => x)) + test[scpi.ParSeq[_] ]((scpi.ParSeq(1): sc.GenSeq[Int] ).map(x => x)) + test[scpi.ParVector[_] ]((scpi.ParVector(1): sc.GenTraversable[Int]).map(x => x)) + test[scpi.ParVector[_] ]((scpi.ParVector(1): sc.GenSeq[Int] ).map(x => x)) + test[scpi.ParSet[_] ]((scpi.ParSet(1): sc.GenTraversable[Int]).map(x => x)) + test[scpi.ParSet[_] ]((scpi.ParSet(1): sc.GenSet[Int] ).map(x => x)) + test[scpi.ParHashSet[_] ]((scpi.ParHashSet(1): sc.GenTraversable[Int]).map(x => x)) + test[scpi.ParHashSet[_] ]((scpi.ParHashSet(1): sc.GenSet[Int] ).map(x => x)) + + // These go through `GenMap.canBuildFrom`. There is no simple fix for Map like there is for Set. + // A Map does not provide access to its companion object at runtime. (The `companion` field + // points to an inherited `GenericCompanion`, not the actual companion object). Therefore, the + // `MapCanBuildFrom` has no way to get the correct builder for the source type at runtime. + //test[scm.Map[_, _] ]((scm.Map(1 -> 1): sc.GenMap[Int, Int]).map(x => x) + //test[scm.OpenHashMap[_, _] ]((scm.OpenHashMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[scm.LongMap[_] ]((scm.LongMap(1L -> 1): sc.GenMap[Long, Int]).map(x => x)) + //test[scm.ListMap[_, _] ]((scm.ListMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[scm.LinkedHashMap[_, _]]((scm.LinkedHashMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[scm.HashMap[_, _] ]((scm.HashMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[sci.Map[_, _] ]((sci.Map(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[sci.ListMap[_, _] ]((sci.ListMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[sci.IntMap[_] ]((sci.IntMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[sci.LongMap[_] ]((sci.LongMap(1L -> 1): sc.GenMap[Long, Int]).map(x => x)) + //test[sci.HashMap[_, _] ]((sci.HashMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[sci.SortedMap[_, _] ]((sci.SortedMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[sci.TreeMap[_, _] ]((sci.TreeMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[scc.TrieMap[_, _] ]((scc.TrieMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[scp.ParMap[_, _] ]((scp.ParMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[scpm.ParMap[_, _] ]((scpm.ParMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[scpm.ParHashMap[_, _] ]((scpm.ParHashMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[scpm.ParTrieMap[_, _] ]((scpm.ParTrieMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[scpi.ParMap[_, _] ]((scpi.ParMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[scpi.ParHashMap[_, _] ]((scpi.ParHashMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + + // These cannot be expected to work. The static type information is lost, and `map` does not capture + // a `ClassTag` of the result type, so there is no way for a `CanBuildFrom` to decide to build another + // `BitSet` instead of a generic `Set` implementation: + //test[scm.BitSet ]((scm.BitSet(1): sc.GenTraversable[Int]).map(x => x)) + //test[scm.BitSet ]((scm.BitSet(1): sc.Set[Int]).map(x => x)) + + // These also require a `ClassTag`: + //test[scm.UnrolledBuffer[_]]((scm.UnrolledBuffer(1): sc.GenTraversable[Int]).map(x => x)) + //test[scm.UnrolledBuffer[_]]((scm.UnrolledBuffer(1): sc.Seq[Int]).map(x => x)) + + // The situation is similar for sorted collection. They require an implicit `Ordering` which cannot + // be captured at runtime by a `CanBuildFrom` when the static type has been lost: + //test[sc.SortedMap[_, _] ]((sc.SortedMap(1 -> 1): sc.GenTraversable[(Int, Int)]).map(x => x)) + //test[sc.SortedMap[_, _] ]((sc.SortedMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[sc.SortedSet[_] ]((sc.SortedSet(1): sc.GenTraversable[Int]).map(x => x)) + //test[sc.SortedSet[_] ]((sc.SortedSet(1): sc.Set[Int]).map(x => x)) + //test[scm.SortedSet[_] ]((scm.SortedSet(1): sc.GenTraversable[Int]).map(x => x)) + //test[scm.SortedSet[_] ]((scm.SortedSet(1): sc.Set[Int]).map(x => x)) + //test[scm.TreeSet[_] ]((scm.TreeSet(1): sc.GenTraversable[Int]).map(x => x)) + //test[scm.TreeSet[_] ]((scm.TreeSet(1): sc.Set[Int]).map(x => x)) + //test[scm.TreeMap[_, _] ]((scm.TreeMap(1 -> 1): sc.GenTraversable[(Int, Int)]).map(x => x)) + //test[scm.TreeMap[_, _] ]((scm.TreeMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + //test[scm.SortedMap[_, _] ]((scm.SortedMap(1 -> 1): sc.GenTraversable[(Int, Int)]).map(x => x)) + //test[scm.SortedMap[_, _] ]((scm.SortedMap(1 -> 1): sc.GenMap[Int, Int]).map(x => x)) + + // Maps do not map to maps when seen as GenTraversable. This would require knowledge that `map` + // returns a `Tuple2`, which is not available dynamically: + //test[sc.GenMap[_, _] ]((sc.GenMap(1 -> 1): sc.GenTraversable[(Int, Int)]).map(x => x)) + //test[sc.Map[_, _] ]((sc.Map(1 -> 1): sc.GenTraversable[(Int, Int)]).map(x => x)) + } +} diff --git a/test/junit/scala/collection/ReusableBuildersTest.scala b/test/junit/scala/collection/ReusableBuildersTest.scala new file mode 100644 index 0000000000..8dd1a37adf --- /dev/null +++ b/test/junit/scala/collection/ReusableBuildersTest.scala @@ -0,0 +1,48 @@ +package scala.collection + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test + +/* Tests various maps by making sure they all agree on the same answers. */ +@RunWith(classOf[JUnit4]) +class ReusableBuildersTest { + // GrowingBuilders are NOT reusable but can clear themselves + @Test + def test_SI8648() { + val b = collection.mutable.HashSet.newBuilder[Int] + b += 3 + b.clear + assert(!b.isInstanceOf[collection.mutable.ReusableBuilder[_,_]]) + assert(b.isInstanceOf[collection.mutable.GrowingBuilder[_,_]]) + assert(b.result == Set[Int]()) + } + + // ArrayBuilders ARE reusable, regardless of whether they returned their internal array or not + @Test + def test_SI9564() { + val b = Array.newBuilder[Float] + b += 3f + val three = b.result + b.clear + b ++= (1 to 16).map(_.toFloat) + val sixteen = b.result + b.clear + b += 0f + val zero = b.result + assert(b.isInstanceOf[collection.mutable.ReusableBuilder[_,_]]) + assert(three.toList == 3 :: Nil) + assert(sixteen.toList == (1 to 16)) + assert(zero.toList == 0 :: Nil) + } + + @Test + def test_reusability() { + val bl = List.newBuilder[String] + val bv = Vector.newBuilder[String] + val ba = collection.mutable.ArrayBuffer.newBuilder[String] + assert(bl.isInstanceOf[collection.mutable.ReusableBuilder[_, _]]) + assert(bv.isInstanceOf[collection.mutable.ReusableBuilder[_, _]]) + assert(!ba.isInstanceOf[collection.mutable.ReusableBuilder[_, _]]) + } +} diff --git a/test/junit/scala/collection/SeqLikeTest.scala b/test/junit/scala/collection/SeqLikeTest.scala new file mode 100644 index 0000000000..2ab682299d --- /dev/null +++ b/test/junit/scala/collection/SeqLikeTest.scala @@ -0,0 +1,19 @@ +package scala.collection + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Assert._ +import org.junit.Test + +@RunWith(classOf[JUnit4]) +class SeqLikeTest { + + @Test def `SI-9936 indexWhere`(): Unit = { + assertEquals(2, "abcde".indexOf('c', -1)) + assertEquals(2, "abcde".indexOf('c', -2)) + assertEquals(2, "abcde".toVector.indexOf('c', -1)) + assertEquals(2, "abcde".toVector.indexOf('c', -2)) + assertEquals(2, "abcde".toVector.indexWhere(_ == 'c', -1)) + assertEquals(2, "abcde".toVector.indexWhere(_ == 'c', -2)) + } +} diff --git a/test/junit/scala/collection/SeqViewTest.scala b/test/junit/scala/collection/SeqViewTest.scala new file mode 100644 index 0000000000..24474fc4b9 --- /dev/null +++ b/test/junit/scala/collection/SeqViewTest.scala @@ -0,0 +1,16 @@ +package scala.collection + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Assert._ +import org.junit.Test + +@RunWith(classOf[JUnit4]) +class SeqViewTest { + + @Test + def test_SI8691() { + // Really just testing to make sure ++: doesn't throw an exception + assert( Seq(1,2) ++: Seq(3,4).view == Seq(1,2,3,4) ) + } +} diff --git a/test/junit/scala/collection/SetMapConsistencyTest.scala b/test/junit/scala/collection/SetMapConsistencyTest.scala index 261c11a98b..eb864a8449 100644 --- a/test/junit/scala/collection/SetMapConsistencyTest.scala +++ b/test/junit/scala/collection/SetMapConsistencyTest.scala @@ -66,6 +66,8 @@ class SetMapConsistencyTest { def boxMhm[A] = new BoxMutableMap[A, cm.HashMap[A, Int]](new cm.HashMap[A, Int], "mutable.HashMap") def boxMohm[A] = new BoxMutableMap[A, cm.OpenHashMap[A, Int]](new cm.OpenHashMap[A, Int], "mutable.OpenHashMap") + + def boxMtm[A: Ordering] = new BoxMutableMap[A, cm.TreeMap[A, Int]](new cm.TreeMap[A, Int], "mutable.TreeMap") def boxMarm[A <: AnyRef] = new BoxMutableMap[A, cm.AnyRefMap[A, Int]](new cm.AnyRefMap[A, Int](_ => -1), "mutable.AnyRefMap") { private def arm: cm.AnyRefMap[A, Int] = m.asInstanceOf[cm.AnyRefMap[A, Int]] @@ -188,7 +190,9 @@ class SetMapConsistencyTest { def boxMbs = new BoxMutableSet[Int, cm.BitSet](new cm.BitSet, "mutable.BitSet") def boxMhs[A] = new BoxMutableSet[A, cm.HashSet[A]](new cm.HashSet[A], "mutable.HashSet") - + + def boxMts[A: Ordering] = new BoxMutableSet[A, cm.TreeSet[A]](new cm.TreeSet[A], "mutable.TreeSet") + def boxJavaS[A] = new BoxMutableSet[A, cm.Set[A]]((new java.util.HashSet[A]).asScala, "java.util.HashSet") { override def adders = 3 override def subbers = 1 @@ -315,7 +319,7 @@ class SetMapConsistencyTest { @Test def churnIntMaps() { val maps = Array[() => MapBox[Int]]( - () => boxMlm[Int], () => boxMhm[Int], () => boxMohm[Int], () => boxJavaM[Int], + () => boxMlm[Int], () => boxMhm[Int], () => boxMohm[Int], () => boxMtm[Int], () => boxJavaM[Int], () => boxIim, () => boxIhm[Int], () => boxIlm[Int], () => boxItm[Int] ) assert( maps.sliding(2).forall{ ms => churn(ms(0)(), ms(1)(), intKeys, 2000) } ) @@ -325,7 +329,7 @@ class SetMapConsistencyTest { def churnLongMaps() { val maps = Array[() => MapBox[Long]]( () => boxMjm, () => boxIjm, () => boxJavaM[Long], - () => boxMlm[Long], () => boxMhm[Long], () => boxMohm[Long], () => boxIhm[Long], () => boxIlm[Long] + () => boxMlm[Long], () => boxMhm[Long], () => boxMtm[Long], () => boxMohm[Long], () => boxIhm[Long], () => boxIlm[Long] ) assert( maps.sliding(2).forall{ ms => churn(ms(0)(), ms(1)(), longKeys, 10000) } ) } @@ -352,7 +356,7 @@ class SetMapConsistencyTest { def churnIntSets() { val sets = Array[() => MapBox[Int]]( () => boxMhm[Int], () => boxIhm[Int], () => boxJavaS[Int], - () => boxMbs, () => boxMhs[Int], () => boxIbs, () => boxIhs[Int], () => boxIls[Int], () => boxIts[Int] + () => boxMbs, () => boxMhs[Int], () => boxMts[Int], () => boxIbs, () => boxIhs[Int], () => boxIls[Int], () => boxIts[Int] ) assert( sets.sliding(2).forall{ ms => churn(ms(0)(), ms(1)(), smallKeys, 1000, valuer = _ => 0) } ) } @@ -529,4 +533,15 @@ class SetMapConsistencyTest { assert(nit == 4) assert(nfe == 4) } + + @Test + def test_SI8727() { + import scala.tools.testing.AssertUtil._ + type NSEE = NoSuchElementException + val map = Map(0 -> "zero", 1 -> "one") + val m = map.filterKeys(i => if (map contains i) true else throw new NSEE) + assert{ (m contains 0) && (m get 0).nonEmpty } + assertThrows[NSEE]{ m contains 2 } + assertThrows[NSEE]{ m get 2 } + } } diff --git a/test/junit/scala/collection/TraversableLikeTest.scala b/test/junit/scala/collection/TraversableLikeTest.scala new file mode 100644 index 0000000000..f703abf3e4 --- /dev/null +++ b/test/junit/scala/collection/TraversableLikeTest.scala @@ -0,0 +1,69 @@ +package scala.collection + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +object TraversableLikeTest { + abstract class FakeIndexedSeq[A] extends IndexedSeq[A] { + def apply(i: Int): A = ??? + def length: Int = 0 + } +} + +@RunWith(classOf[JUnit4]) +class TraversableLikeTest { + import TraversableLikeTest._ + + // For test_SI9019; out here because as of test writing, putting this in a method would crash compiler + class Baz[@specialized(Int) A]() extends IndexedSeq[A] { + def apply(i: Int) = ??? + def length: Int = 0 + } + + @Test + def test_SI9019 { + object Foo { + def mkBar = () => { + class Bar extends FakeIndexedSeq[Int] + new Bar + } + + def mkFalsePositiveToSyntheticTest = () => { + /* A class whose name tarts with an ASCII lowercase letter. + * It will be a false positive to the synthetic-part test. + */ + class falsePositive extends FakeIndexedSeq[Int] + new falsePositive + } + + def mkFrench = () => { + // For non-French speakers, this means "strange class name" + class ÉtrangeNomDeClasse extends FakeIndexedSeq[Int] + new ÉtrangeNomDeClasse + } + + def mkFrenchLowercase = () => { + class étrangeNomDeClasseMinuscules extends FakeIndexedSeq[Int] + new étrangeNomDeClasseMinuscules + } + } + + val bar = Foo.mkBar() + assertEquals("Bar", bar.stringPrefix) // Previously would have been outermost class, TraversableLikeTest + + val baz = new Baz[Int]() + assertEquals("TraversableLikeTest.Baz", baz.stringPrefix) // Make sure we don't see specialization $mcI$sp stuff + + // The false positive unfortunately produces an empty stringPrefix + val falsePositive = Foo.mkFalsePositiveToSyntheticTest() + assertEquals("", falsePositive.stringPrefix) + + val french = Foo.mkFrench() + assertEquals("ÉtrangeNomDeClasse", french.stringPrefix) + + val frenchLowercase = Foo.mkFrenchLowercase() + assertEquals("étrangeNomDeClasseMinuscules", frenchLowercase.stringPrefix) + } +} diff --git a/test/junit/scala/collection/concurrent/TrieMapTest.scala b/test/junit/scala/collection/concurrent/TrieMapTest.scala new file mode 100644 index 0000000000..ed67f3e9a9 --- /dev/null +++ b/test/junit/scala/collection/concurrent/TrieMapTest.scala @@ -0,0 +1,54 @@ +package scala.collection.concurrent + +import org.junit.{Assert, Test} + +class TrieMapTest { + + private def check[T](result2: List[Any])(f: TrieMap[String, String] => TraversableOnce[Any]) = { + val m = TrieMap[String, String]() + val values = f(m) + m.put("k", "v") + Assert.assertEquals(Nil, values.toList) + Assert.assertEquals(result2, f(m).toList) + } + + @Test + def iterator(): Unit = { + check(List(("k", "v")))(_.iterator) + } + + @Test + def values(): Unit = { + check(List("v"))(_.values) + } + + @Test + def valuesIterator(): Unit = { + check(List("v"))(_.valuesIterator) + } + + @Test + def keySet(): Unit = { + check(List("k"))(_.keySet) + } + + @Test + def keysIterator(): Unit = { + check(List("k"))(_.keysIterator) + } + + @Test + def keys(): Unit = { + check(List("k"))(_.keys) + } + + @Test + def filterKeys(): Unit = { + check(List(("k", "v")))(_.filterKeys(_ => true)) + } + + @Test + def mapValues(): Unit = { + check(List(("k", "v")))(_.mapValues(x => x)) + } +} diff --git a/test/junit/scala/collection/convert/NullSafetyToJavaTest.scala b/test/junit/scala/collection/convert/NullSafetyToJavaTest.scala new file mode 100644 index 0000000000..da0513ed8a --- /dev/null +++ b/test/junit/scala/collection/convert/NullSafetyToJavaTest.scala @@ -0,0 +1,138 @@ +package scala.collection.convert + +import java.util.{concurrent => juc} +import java.{lang => jl, util => ju} + +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +import scala.collection.JavaConverters._ +import scala.collection.convert.ImplicitConversions._ +import scala.collection.{concurrent, mutable} + +// SI-9113: tests to insure that wrappers return null instead of wrapping it as a collection + +@RunWith(classOf[JUnit4]) +class NullSafetyToJavaTest { + @Test def testIteratorWrapping(): Unit = { + val nullIterator: Iterator[AnyRef] = null + val jIterator: ju.Iterator[AnyRef] = nullIterator + + assert(jIterator == null) + } + + @Test def testEnumerationWrapping(): Unit = { + val nullEnumeration: Iterator[AnyRef] = null + val enumeration: ju.Iterator[AnyRef] = nullEnumeration + + assert(enumeration == null) + } + + @Test def testIterableWrapping(): Unit = { + val nullIterable: Iterable[AnyRef] = null + val iterable: jl.Iterable[AnyRef] = asJavaIterable(nullIterable) + + assert(iterable == null) + } + + @Test def testCollectionWrapping(): Unit = { + val nullCollection: Iterable[AnyRef] = null + val collection: ju.Collection[AnyRef] = nullCollection + + assert(collection == null) + } + + @Test def testBufferWrapping(): Unit = { + val nullList: mutable.Buffer[AnyRef] = null + val buffer: ju.List[AnyRef] = nullList + + assert(buffer == null) + } + + @Test def testSetWrapping(): Unit = { + val nullSet: mutable.Set[AnyRef] = null + val set: ju.Set[AnyRef] = nullSet + + assert(set == null) + } + + @Test def testMapWrapping(): Unit = { + val nullMap: mutable.Map[AnyRef, AnyRef] = null + val map: ju.Map[AnyRef, AnyRef] = nullMap + + assert(map == null) + } + + @Test def testConcurrentMapWrapping(): Unit = { + val nullConMap: concurrent.Map[AnyRef, AnyRef] = null + val conMap: juc.ConcurrentMap[AnyRef, AnyRef] = nullConMap + + assert(conMap == null) + } + + @Test def testDictionaryWrapping(): Unit = { + val nullDict: mutable.Map[AnyRef, AnyRef] = null + val dict: ju.Dictionary[AnyRef, AnyRef] = nullDict + + assert(dict == null) + } + + // Implicit conversion to ju.Properties is not available + + @Test def testIteratorDecoration(): Unit = { + val nullIterator: Iterator[AnyRef] = null + + assert(nullIterator.asJava == null) + } + + @Test def testEnumerationDecoration(): Unit = { + val nullEnumeration: Iterator[AnyRef] = null + + assert(nullEnumeration.asJavaEnumeration == null) + } + + @Test def testIterableDecoration(): Unit = { + val nullIterable: Iterable[AnyRef] = null + + assert(nullIterable.asJava == null) + } + + @Test def testCollectionDecoration(): Unit = { + val nullCollection: Iterable[AnyRef] = null + + assert(nullCollection.asJavaCollection == null) + } + + @Test def testBufferDecoration(): Unit = { + val nullBuffer: mutable.Buffer[AnyRef] = null + + assert(nullBuffer.asJava == null) + } + + @Test def testSetDecoration(): Unit = { + val nullSet: Set[AnyRef] = null + + assert(nullSet.asJava == null) + } + + @Test def testMapDecoration(): Unit = { + val nullMap: mutable.Map[AnyRef, AnyRef] = null + + assert(nullMap.asJava == null) + } + + @Test def testConcurrentMapDecoration(): Unit = { + val nullConMap: concurrent.Map[AnyRef, AnyRef] = null + + assert(nullConMap.asJava == null) + } + + @Test def testDictionaryDecoration(): Unit = { + val nullDict: mutable.Map[AnyRef, AnyRef] = null + + assert(nullDict.asJavaDictionary == null) + } + + // Decorator conversion to ju.Properties is not available +} diff --git a/test/junit/scala/collection/convert/NullSafetyToScalaTest.scala b/test/junit/scala/collection/convert/NullSafetyToScalaTest.scala new file mode 100644 index 0000000000..9b6d366faf --- /dev/null +++ b/test/junit/scala/collection/convert/NullSafetyToScalaTest.scala @@ -0,0 +1,148 @@ +package scala.collection.convert + +import java.util.{concurrent => juc} +import java.{lang => jl, util => ju} + +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +import scala.collection.JavaConverters._ +import scala.collection.convert.ImplicitConversions._ +import scala.collection.{concurrent, mutable} + +// SI-9113: tests to insure that wrappers return null instead of wrapping it as a collection + +@RunWith(classOf[JUnit4]) +class NullSafetyToScalaTest { + @Test def testIteratorWrapping(): Unit = { + val nullJIterator: ju.Iterator[AnyRef] = null + val iterator: Iterator[AnyRef] = nullJIterator + + assert(iterator == null) + } + + @Test def testEnumerationWrapping(): Unit = { + val nullJEnumeration: ju.Enumeration[AnyRef] = null + val enumeration: Iterator[AnyRef] = nullJEnumeration + + assert(enumeration == null) + } + + @Test def testIterableWrapping(): Unit = { + val nullJIterable: jl.Iterable[AnyRef] = null + val iterable: Iterable[AnyRef] = nullJIterable + + assert(iterable == null) + } + + @Test def testCollectionWrapping(): Unit = { + val nullJCollection: ju.Collection[AnyRef] = null + val collection: Iterable[AnyRef] = nullJCollection + + assert(collection == null) + } + + @Test def testBufferWrapping(): Unit = { + val nullJList: ju.List[AnyRef] = null + val buffer: mutable.Buffer[AnyRef] = nullJList + + assert(buffer == null) + } + + @Test def testSetWrapping(): Unit = { + val nullJSet: ju.Set[AnyRef] = null + val set: mutable.Set[AnyRef] = nullJSet + + assert(set == null) + } + + @Test def testMapWrapping(): Unit = { + val nullJMap: ju.Map[AnyRef, AnyRef] = null + val map: mutable.Map[AnyRef, AnyRef] = nullJMap + + assert(map == null) + } + + @Test def testConcurrentMapWrapping(): Unit = { + val nullJConMap: juc.ConcurrentMap[AnyRef, AnyRef] = null + val conMap: concurrent.Map[AnyRef, AnyRef] = nullJConMap + + assert(conMap == null) + } + + @Test def testDictionaryWrapping(): Unit = { + val nullJDict: ju.Dictionary[AnyRef, AnyRef] = null + val dict: mutable.Map[AnyRef, AnyRef] = nullJDict + + assert(dict == null) + } + + + @Test def testPropertyWrapping(): Unit = { + val nullJProps: ju.Properties = null + val props: mutable.Map[String, String] = nullJProps + + assert(props == null) + } + + @Test def testIteratorDecoration(): Unit = { + val nullJIterator: ju.Iterator[AnyRef] = null + + assert(nullJIterator.asScala == null) + } + + @Test def testEnumerationDecoration(): Unit = { + val nullJEnumeration: ju.Enumeration[AnyRef] = null + + assert(nullJEnumeration.asScala == null) + } + + @Test def testIterableDecoration(): Unit = { + val nullJIterable: jl.Iterable[AnyRef] = null + + assert(nullJIterable.asScala == null) + } + + @Test def testCollectionDecoration(): Unit = { + val nullJCollection: ju.Collection[AnyRef] = null + + assert(nullJCollection.asScala == null) + } + + @Test def testBufferDecoration(): Unit = { + val nullJBuffer: ju.List[AnyRef] = null + + assert(nullJBuffer.asScala == null) + } + + @Test def testSetDecoration(): Unit = { + val nullJSet: ju.Set[AnyRef] = null + + assert(nullJSet.asScala == null) + } + + @Test def testMapDecoration(): Unit = { + val nullJMap: ju.Map[AnyRef, AnyRef] = null + + assert(nullJMap.asScala == null) + } + + @Test def testConcurrentMapDecoration(): Unit = { + val nullJConMap: juc.ConcurrentMap[AnyRef, AnyRef] = null + + assert(nullJConMap.asScala == null) + } + + @Test def testDictionaryDecoration(): Unit = { + val nullJDict: ju.Dictionary[AnyRef, AnyRef] = null + + assert(nullJDict.asScala == null) + } + + @Test def testPropertiesDecoration(): Unit = { + val nullJProperties: ju.Properties = null + + assert(nullJProperties.asScala == null) + } +} diff --git a/test/junit/scala/collection/convert/WrapperSerializationTest.scala b/test/junit/scala/collection/convert/WrapperSerializationTest.scala new file mode 100644 index 0000000000..d398be806a --- /dev/null +++ b/test/junit/scala/collection/convert/WrapperSerializationTest.scala @@ -0,0 +1,29 @@ +package scala.collection.convert + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(classOf[JUnit4]) +class WrapperSerializationTest { + def ser(a: AnyRef) = { + val baos = new java.io.ByteArrayOutputStream + (new java.io.ObjectOutputStream(baos)).writeObject(a) + baos + } + def des(baos: java.io.ByteArrayOutputStream): AnyRef = { + val bais = new java.io.ByteArrayInputStream(baos.toByteArray) + (new java.io.ObjectInputStream(bais)).readObject() + } + def serdes(a: AnyRef): Boolean = a == des(ser(a)) + + @Test + def test_SI8911() { + import scala.collection.JavaConverters._ + assert( serdes(scala.collection.mutable.ArrayBuffer(1,2).asJava) ) + assert( serdes(Seq(1,2).asJava) ) + assert( serdes(Set(1,2).asJava) ) + assert( serdes(Map(1 -> "one", 2 -> "two").asJava) ) + } +} diff --git a/test/junit/scala/collection/immutable/ListMapTest.scala b/test/junit/scala/collection/immutable/ListMapTest.scala new file mode 100644 index 0000000000..320a976755 --- /dev/null +++ b/test/junit/scala/collection/immutable/ListMapTest.scala @@ -0,0 +1,48 @@ +package scala.collection.immutable + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(classOf[JUnit4]) +class ListMapTest { + + @Test + def t7445(): Unit = { + val m = ListMap(1 -> 1, 2 -> 2, 3 -> 3, 4 -> 4, 5 -> 5) + assertEquals(ListMap(2 -> 2, 3 -> 3, 4 -> 4, 5 -> 5), m.tail) + } + + @Test + def hasCorrectBuilder(): Unit = { + val m = ListMap("a" -> "1", "b" -> "2", "c" -> "3", "b" -> "2.2", "d" -> "4") + assertEquals(List("a" -> "1", "c" -> "3", "b" -> "2.2", "d" -> "4"), m.toList) + } + + @Test + def hasCorrectHeadTailLastInit(): Unit = { + val m = ListMap(1 -> 1, 2 -> 2, 3 -> 3) + assertEquals(1 -> 1, m.head) + assertEquals(ListMap(2 -> 2, 3 -> 3), m.tail) + assertEquals(3 -> 3, m.last) + assertEquals(ListMap(1 -> 1, 2 -> 2), m.init) + } + + @Test + def hasCorrectAddRemove(): Unit = { + val m = ListMap(1 -> 1, 2 -> 2, 3 -> 3) + assertEquals(ListMap(1 -> 1, 2 -> 2, 3 -> 3, 4 -> 4), m + (4 -> 4)) + assertEquals(ListMap(1 -> 1, 3 -> 3, 2 -> 4), m + (2 -> 4)) + assertEquals(ListMap(1 -> 1, 2 -> 2, 3 -> 3), m + (2 -> 2)) + assertEquals(ListMap(2 -> 2, 3 -> 3), m - 1) + assertEquals(ListMap(1 -> 1, 3 -> 3), m - 2) + assertEquals(ListMap(1 -> 1, 2 -> 2, 3 -> 3), m - 4) + } + + @Test + def hasCorrectIterator(): Unit = { + val m = ListMap(1 -> 1, 2 -> 2, 3 -> 3, 5 -> 5, 4 -> 4) + assertEquals(List(1 -> 1, 2 -> 2, 3 -> 3, 5 -> 5, 4 -> 4), m.iterator.toList) + } +} diff --git a/test/junit/scala/collection/immutable/ListSetTest.scala b/test/junit/scala/collection/immutable/ListSetTest.scala new file mode 100644 index 0000000000..395da88c75 --- /dev/null +++ b/test/junit/scala/collection/immutable/ListSetTest.scala @@ -0,0 +1,53 @@ +package scala.collection.immutable + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(classOf[JUnit4]) +class ListSetTest { + + @Test + def t7445(): Unit = { + val s = ListSet(1, 2, 3, 4, 5) + assertEquals(ListSet(2, 3, 4, 5), s.tail) + } + + @Test + def hasCorrectBuilder(): Unit = { + val m = ListSet("a", "b", "c", "b", "d") + assertEquals(List("a", "b", "c", "d"), m.toList) + } + + @Test + def hasTailRecursiveDelete(): Unit = { + val s = ListSet(1 to 50000: _*) + try s - 25000 catch { case e: StackOverflowError => fail("A stack overflow occurred") } + } + + @Test + def hasCorrectHeadTailLastInit(): Unit = { + val m = ListSet(1, 2, 3) + assertEquals(1, m.head) + assertEquals(ListSet(2, 3), m.tail) + assertEquals(3, m.last) + assertEquals(ListSet(1, 2), m.init) + } + + @Test + def hasCorrectAddRemove(): Unit = { + val m = ListSet(1, 2, 3) + assertEquals(ListSet(1, 2, 3, 4), m + 4) + assertEquals(ListSet(1, 2, 3), m + 2) + assertEquals(ListSet(2, 3), m - 1) + assertEquals(ListSet(1, 3), m - 2) + assertEquals(ListSet(1, 2, 3), m - 4) + } + + @Test + def hasCorrectIterator(): Unit = { + val s = ListSet(1, 2, 3, 5, 4) + assertEquals(List(1, 2, 3, 5, 4), s.iterator.toList) + } +} diff --git a/test/junit/scala/collection/immutable/PagedSeqTest.scala b/test/junit/scala/collection/immutable/PagedSeqTest.scala index 74f8825307..6c974db884 100644 --- a/test/junit/scala/collection/immutable/PagedSeqTest.scala +++ b/test/junit/scala/collection/immutable/PagedSeqTest.scala @@ -2,13 +2,14 @@ package scala.collection.immutable import org.junit.runner.RunWith import org.junit.runners.JUnit4 -import org.junit.Test +import org.junit.{Ignore, Test} import org.junit.Assert._ @RunWith(classOf[JUnit4]) class PagedSeqTest { // should not NPE, and should equal the given Seq @Test + @Ignore("This tests a non-stack safe method in a deprecated class that requires ~1.5M stack, disabling") def test_SI6615(): Unit = { assertEquals(Seq('a'), PagedSeq.fromStrings(List.fill(5000)("a")).slice(4096, 4097)) } diff --git a/test/junit/scala/collection/immutable/RangeTest.scala b/test/junit/scala/collection/immutable/RangeTest.scala new file mode 100644 index 0000000000..a0bef72bc9 --- /dev/null +++ b/test/junit/scala/collection/immutable/RangeTest.scala @@ -0,0 +1,42 @@ +package scala.collection.immutable + +import org.junit.{Assert, Test} +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import scala.tools.testing.AssertUtil + +@RunWith(classOf[JUnit4]) +class RangeTest { + import Assert._ + import AssertUtil._ + + @Test + def test_SI10060_numeric_range_min_max(): Unit = { + assertEquals(Range.Long.inclusive(1, 9, 1).min, 1) + assertEquals(Range.Long.inclusive(1, 9, 1).max, 9) + assertEquals(Range.Long.inclusive(9, 1, -1).min, 1) + assertEquals(Range.Long.inclusive(9, 1, -1).max, 9) + assertThrows[java.util.NoSuchElementException](Range.Long.inclusive(1, 9, -1).min) + assertThrows[java.util.NoSuchElementException](Range.Long.inclusive(1, 9, -1).max) + assertThrows[java.util.NoSuchElementException](Range.Long.inclusive(9, 1, 1).min) + assertThrows[java.util.NoSuchElementException](Range.Long.inclusive(9, 1, 1).max) + + assertEquals(Range.Int.inclusive(1, 9, 1).min, 1) + assertEquals(Range.Int.inclusive(1, 9, 1).max, 9) + assertEquals(Range.Int.inclusive(9, 1, -1).min, 1) + assertEquals(Range.Int.inclusive(9, 1, -1).max, 9) + assertThrows[java.util.NoSuchElementException](Range.Int.inclusive(1, 9, -1).min) + assertThrows[java.util.NoSuchElementException](Range.Int.inclusive(1, 9, -1).max) + assertThrows[java.util.NoSuchElementException](Range.Int.inclusive(9, 1, 1).min) + assertThrows[java.util.NoSuchElementException](Range.Int.inclusive(9, 1, 1).max) + + assertEquals(Range.inclusive(1, 9, 1).min, 1) + assertEquals(Range.inclusive(1, 9, 1).max, 9) + assertEquals(Range.inclusive(9, 1, -1).min, 1) + assertEquals(Range.inclusive(9, 1, -1).max, 9) + assertThrows[java.util.NoSuchElementException](Range.inclusive(1, 9, -1).min) + assertThrows[java.util.NoSuchElementException](Range.inclusive(1, 9, -1).max) + assertThrows[java.util.NoSuchElementException](Range.inclusive(9, 1, 1).min) + assertThrows[java.util.NoSuchElementException](Range.inclusive(9, 1, 1).max) + } +} diff --git a/test/junit/scala/collection/immutable/SetTests.scala b/test/junit/scala/collection/immutable/SetTest.scala index 28c7864359..4029c98009 100644 --- a/test/junit/scala/collection/immutable/SetTests.scala +++ b/test/junit/scala/collection/immutable/SetTest.scala @@ -6,7 +6,7 @@ import org.junit.runner.RunWith import org.junit.runners.JUnit4 @RunWith(classOf[JUnit4]) -class SetTests { +class SetTest { @Test def test_SI8346_toSet_soundness(): Unit = { val any2stringadd = "Disabled string conversions so as not to get confused!" diff --git a/test/junit/scala/collection/immutable/StreamTest.scala b/test/junit/scala/collection/immutable/StreamTest.scala new file mode 100644 index 0000000000..61f7b792e8 --- /dev/null +++ b/test/junit/scala/collection/immutable/StreamTest.scala @@ -0,0 +1,126 @@ +package scala.collection.immutable + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import org.junit.Assert._ + +import scala.ref.WeakReference +import scala.util.Try + +@RunWith(classOf[JUnit4]) +class StreamTest { + + @Test + def t6727_and_t6440_and_8627(): Unit = { + assertTrue(Stream.continually(()).filter(_ => true).take(2) == Seq((), ())) + assertTrue(Stream.continually(()).filterNot(_ => false).take(2) == Seq((), ())) + assertTrue(Stream(1,2,3,4,5).filter(_ < 4) == Seq(1,2,3)) + assertTrue(Stream(1,2,3,4,5).filterNot(_ > 4) == Seq(1,2,3,4)) + assertTrue(Stream.from(1).filter(_ > 4).take(3) == Seq(5,6,7)) + assertTrue(Stream.from(1).filterNot(_ <= 4).take(3) == Seq(5,6,7)) + } + + /** Test helper to verify that the given Stream operation allows + * GC of the head during processing of the tail. + */ + def assertStreamOpAllowsGC(op: (=> Stream[Int], Int => Unit) => Any, f: Int => Unit): Unit = { + val msgSuccessGC = "GC success" + val msgFailureGC = "GC failure" + + // A stream of 500 elements at most. We will test that the head can be collected + // while processing the tail. After each element we will GC and wait 10 ms, so a + // failure to collect will take roughly 5 seconds. + val ref = WeakReference( Stream.from(1).take(500) ) + + def gcAndThrowIfCollected(n: Int): Unit = { + System.gc() // try to GC + Thread.sleep(10) // give it 10 ms + if (ref.get.isEmpty) throw new RuntimeException(msgSuccessGC) // we're done if head collected + f(n) + } + + val res = Try { op(ref(), gcAndThrowIfCollected) }.failed // success is indicated by an + val msg = res.map(_.getMessage).getOrElse(msgFailureGC) // exception with expected message + // failure is indicated by no + assertTrue(msg == msgSuccessGC) // exception, or one with different message + } + + @Test + def foreach_allows_GC() { + assertStreamOpAllowsGC(_.foreach(_), _ => ()) + } + + @Test + def filter_all_foreach_allows_GC() { + assertStreamOpAllowsGC(_.filter(_ => true).foreach(_), _ => ()) + } + + @Test // SI-8990 + def withFilter_after_first_foreach_allows_GC: Unit = { + assertStreamOpAllowsGC(_.withFilter(_ > 1).foreach(_), _ => ()) + } + + @Test // SI-8990 + def withFilter_after_first_withFilter_foreach_allows_GC: Unit = { + assertStreamOpAllowsGC(_.withFilter(_ > 1).withFilter(_ < 100).foreach(_), _ => ()) + } + + @Test // SI-8990 + def withFilter_can_retry_after_exception_thrown_in_filter: Unit = { + // use mutable state to control an intermittent failure in filtering the Stream + var shouldThrow = true + + val wf = Stream.from(1).take(10).withFilter { n => + if (shouldThrow && n == 5) throw new RuntimeException("n == 5") else n > 5 + } + + assertTrue( Try { wf.map(identity) }.isFailure ) // throws on n == 5 + + shouldThrow = false // won't throw next time + + assertTrue( wf.map(identity).length == 5 ) // success instead of NPE + } + + /** Test helper to verify that the given Stream operation is properly lazy in the tail */ + def assertStreamOpLazyInTail(op: (=> Stream[Int]) => Stream[Int], expectedEvaluated: List[Int]): Unit = { + // mutable state to record every strict evaluation + var evaluated: List[Int] = Nil + + def trackEffectsOnNaturals: Stream[Int] = { + def loop(i: Int): Stream[Int] = { evaluated ++= List(i); i #:: loop(i + 1) } + loop(1) + } + + // call op on a stream which records every strict evaluation + val result = op(trackEffectsOnNaturals) + + assertTrue( evaluated == expectedEvaluated ) + } + + @Test // SI-9134 + def filter_map_properly_lazy_in_tail: Unit = { + assertStreamOpLazyInTail(_.filter(_ % 2 == 0).map(identity), List(1, 2)) + } + + @Test // SI-9134 + def withFilter_map_properly_lazy_in_tail: Unit = { + assertStreamOpLazyInTail(_.withFilter(_ % 2 == 0).map(identity), List(1, 2)) + } + + @Test // SI-6881 + def test_reference_equality: Unit = { + // Make sure we're tested with reference equality + val s = Stream.from(0) + assert(s == s, "Referentially identical streams should be equal (==)") + assert(s equals s, "Referentially identical streams should be equal (equals)") + assert((0 #:: 1 #:: s) == (0 #:: 1 #:: s), "Cons of referentially identical streams should be equal (==)") + assert((0 #:: 1 #:: s) equals (0 #:: 1 #:: s), "Cons of referentially identical streams should be equal (equals)") + } + + @Test + def t9886: Unit = { + assertEquals(Stream(None, Some(1)), None #:: Stream(Some(1))) + assertEquals(Stream(None, Some(1)), Stream(None) #::: Stream(Some(1))) + } +} diff --git a/test/junit/scala/collection/immutable/StringLikeTest.scala b/test/junit/scala/collection/immutable/StringLikeTest.scala index 3722bdfe4d..44bade860e 100644 --- a/test/junit/scala/collection/immutable/StringLikeTest.scala +++ b/test/junit/scala/collection/immutable/StringLikeTest.scala @@ -1,5 +1,6 @@ package scala.collection.immutable +import org.junit.Assert._ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 @@ -28,10 +29,46 @@ class StringLikeTest { @Test def testSplitEdgeCases: Unit = { + val high = 0xD852.toChar + val low = 0xDF62.toChar + val surrogatepair = List(high, low).mkString + val twopairs = surrogatepair + "_" + surrogatepair + AssertUtil.assertSameElements("abcd".split('d'), Array("abc")) // not Array("abc", "") AssertUtil.assertSameElements("abccc".split('c'), Array("ab")) // not Array("ab", "", "", "") AssertUtil.assertSameElements("xxx".split('x'), Array[String]()) // not Array("", "", "", "") AssertUtil.assertSameElements("".split('x'), Array("")) // not Array() AssertUtil.assertSameElements("--ch--omp--".split("-"), Array("", "", "ch", "", "omp")) // All the cases! + AssertUtil.assertSameElements(twopairs.split(high), Array(twopairs)) //don't split on characters that are half a surrogate pair + } + + /* Test for SI-9767 */ + @Test + def testNumericConversion: Unit = { + val sOne = " \t\n 1 \n\r\t " + val sOk = "2" + val sNull:String = null + + AssertUtil.assertThrows[java.lang.NumberFormatException](sOne.toInt) + AssertUtil.assertThrows[java.lang.NumberFormatException](sOne.toLong) + AssertUtil.assertThrows[java.lang.NumberFormatException](sOne.toShort) + AssertUtil.assertThrows[java.lang.NumberFormatException](sOne.toByte) + assertTrue("trim toDouble", sOne.toDouble == 1.0d) + assertTrue("trim toFloat", sOne.toFloat == 1.0f) + + assertTrue("no trim toInt", sOk.toInt == 2) + assertTrue("no trim toLong", sOk.toLong == 2L) + assertTrue("no trim toShort", sOk.toShort == 2.toShort) + assertTrue("no trim toByte", sOk.toByte == 2.toByte) + assertTrue("no trim toDouble", sOk.toDouble == 2.0d) + assertTrue("no trim toFloat", sOk.toFloat == 2.0f) + + AssertUtil.assertThrows[java.lang.NumberFormatException](sNull.toInt, {s => s == "null"}) + AssertUtil.assertThrows[java.lang.NumberFormatException](sNull.toLong, {s => s == "null"}) + AssertUtil.assertThrows[java.lang.NumberFormatException](sNull.toShort, {s => s == "null"}) + AssertUtil.assertThrows[java.lang.NumberFormatException](sNull.toByte, {s => s == "null"}) + + AssertUtil.assertThrows[java.lang.NullPointerException](sNull.toDouble) + AssertUtil.assertThrows[java.lang.NullPointerException](sNull.toFloat) } } diff --git a/test/junit/scala/collection/mutable/ArrayBuilderTest.scala b/test/junit/scala/collection/mutable/ArrayBuilderTest.scala deleted file mode 100644 index b7190ee5d5..0000000000 --- a/test/junit/scala/collection/mutable/ArrayBuilderTest.scala +++ /dev/null @@ -1,28 +0,0 @@ -package scala.collection.mutable - -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 -import org.junit.Test -import scala.collection.mutable - -@RunWith(classOf[JUnit4]) -class ArrayBuilderTest { - @Test - def reusable() { - val builder = new ArrayBuilder.ofInt - val vector = Vector.range(1, 17) - val expected = Vector.range(1, 17).toArray - - builder ++= vector - val actual = builder.result() - assert ( actual.deep == expected.deep ) - - builder.clear() - val expected2 = Array[Int](100) - builder += 100 - - // Previously created array MUST be immutable even after `result`, `clear` and some operation are called - assert( actual.deep == expected.deep ) - assert( builder.result().deep == expected2.deep ) - } -} diff --git a/test/junit/scala/collection/mutable/BitSetTest.scala b/test/junit/scala/collection/mutable/BitSetTest.scala index d56cc45601..f0a0ef5d75 100644 --- a/test/junit/scala/collection/mutable/BitSetTest.scala +++ b/test/junit/scala/collection/mutable/BitSetTest.scala @@ -1,13 +1,13 @@ package scala.collection.mutable +import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 -import org.junit.{Test, Ignore} @RunWith(classOf[JUnit4]) class BitSetTest { // Test for SI-8910 - @Test def capacityExpansionTest() { + @Test def capacityExpansionTest(): Unit = { val bitSet = BitSet.empty val size = bitSet.toBitMask.length bitSet ^= bitSet @@ -20,7 +20,7 @@ class BitSetTest { assert(bitSet.toBitMask.length == size, "Capacity of bitset changed after &~=") } - @Test def test_SI8917() { + @Test def test_SI8917(): Unit = { val bigBitSet = BitSet(1, 100, 10000) val littleBitSet = BitSet(100) bigBitSet &= littleBitSet @@ -28,4 +28,17 @@ class BitSetTest { littleBitSet &= bigBitSet assert(littleBitSet.toBitMask.length < bigBitSet.toBitMask.length, "Needlessly extended the size of bitset on &=") } + + @Test def test_SI8647(): Unit = { + val bs = BitSet() + bs.map(_ + 1) // Just needs to compile + val xs = bs: SortedSet[Int] + xs.map(_ + 1) // Also should compile (did before) + } + + @Test def t10164(): Unit = { + val bs = BitSet() + val last = (bs ++ (0 to 128)).last // Just needs not to throw + assert(last == 128) + } } diff --git a/test/junit/scala/collection/mutable/HashMapTest.scala b/test/junit/scala/collection/mutable/HashMapTest.scala new file mode 100644 index 0000000000..cc1979a920 --- /dev/null +++ b/test/junit/scala/collection/mutable/HashMapTest.scala @@ -0,0 +1,38 @@ +package scala.collection +package mutable + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(classOf[JUnit4]) +class HashMapTest { + + @Test + def getOrElseUpdate_mutationInCallback() { + val hm = new mutable.HashMap[String, String]() + // add enough elements to resize the hash table in the callback + def add() = 1 to 100000 foreach (i => hm(i.toString) = "callback") + hm.getOrElseUpdate("0", { + add() + "" + }) + assertEquals(Some(""), hm.get("0")) + } + + @Test + def getOrElseUpdate_evalOnce(): Unit = { + var i = 0 + val hm = new mutable.HashMap[Int, Int]() + hm.getOrElseUpdate(0, {i += 1; i}) + assertEquals(1, hm(0)) + } + + @Test + def getOrElseUpdate_noEval(): Unit = { + val hm = new mutable.HashMap[Int, Int]() + hm.put(0, 0) + hm.getOrElseUpdate(0, throw new AssertionError()) + } +} diff --git a/test/junit/scala/collection/mutable/OpenHashMapTest.scala b/test/junit/scala/collection/mutable/OpenHashMapTest.scala index 1459c14d78..e9f2a52bf6 100644 --- a/test/junit/scala/collection/mutable/OpenHashMapTest.scala +++ b/test/junit/scala/collection/mutable/OpenHashMapTest.scala @@ -1,9 +1,10 @@ package scala.collection.mutable -import org.junit.Test import org.junit.Assert._ +import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 +import org.openjdk.jol.info.{GraphPathRecord, GraphVisitor, GraphWalker} /** Tests for [[OpenHashMap]]. */ @RunWith(classOf[JUnit4]) @@ -28,7 +29,13 @@ class OpenHashMapTest { val fieldMirror = mirror.reflect(m).reflectField(termSym) */ // Use Java reflection instead for now. - val field = m.getClass.getDeclaredField("scala$collection$mutable$OpenHashMap$$deleted") + val field = + try { // Name may or not be mangled, depending on what the compiler authors are doing. + m.getClass.getDeclaredField("scala$collection$mutable$OpenHashMap$$deleted") + } catch { + case _: NoSuchFieldException => + m.getClass.getDeclaredField("deleted") + } field.setAccessible(true) m.put(0, 0) @@ -39,4 +46,50 @@ class OpenHashMapTest { // TODO assertEquals(0, fieldMirror.get.asInstanceOf[Int]) assertEquals(0, field.getInt(m)) } + + /** Test that an [[OpenHashMap]] frees references to a deleted key (SI-9522). */ + @Test + def freesDeletedKey { + import scala.language.reflectiveCalls + + class MyClass { + override def hashCode() = 42 + } + + val counter = new GraphVisitor() { + private[this] var instanceCount: Int = _ + + def countInstances(obj: AnyRef) = { + instanceCount = 0 + val walker = new GraphWalker(obj) + walker.addVisitor(this) + walker.walk + instanceCount + } + + override def visit(record: GraphPathRecord) { + if (record.klass() == classOf[MyClass]) instanceCount += 1 + } + } + + val m = OpenHashMap.empty[MyClass, Int] + val obj = new MyClass + assertEquals("Found a key instance in the map before adding one!?", 0, counter.countInstances(m)) + m.put(obj, 0) + assertEquals("There should be only one key instance in the map.", 1, counter.countInstances(m)) + m.put(obj, 1) + assertEquals("There should still be only one key instance in the map.", 1, counter.countInstances(m)) + m.remove(obj) + assertEquals("There should be no key instance in the map.", 0, counter.countInstances(m)) + + val obj2 = new MyClass + assertEquals("The hash codes of the test objects need to match.", obj.##, obj2.##) + m.put(obj, 0) + m.put(obj2, 0) + assertEquals("There should be two key instances in the map.", 2, counter.countInstances(m)) + m.remove(obj) + assertEquals("There should be one key instance in the map.", 1, counter.countInstances(m)) + m.remove(obj2) + assertEquals("There should be no key instance in the map.", 0, counter.countInstances(m)) + } } diff --git a/test/junit/scala/collection/mutable/PriorityQueueTest.scala b/test/junit/scala/collection/mutable/PriorityQueueTest.scala index a14f1bf4c8..faedcf11f0 100644 --- a/test/junit/scala/collection/mutable/PriorityQueueTest.scala +++ b/test/junit/scala/collection/mutable/PriorityQueueTest.scala @@ -14,6 +14,12 @@ class PriorityQueueTest { priorityQueue.enqueue(elements :_*) @Test + def orderingReverseReverse() { + val pq = new mutable.PriorityQueue[Nothing]()((_,_)=>42) + assert(pq.ord eq pq.reverse.reverse.ord) + } + + @Test def canSerialize() { val outputStream = new ByteArrayOutputStream() new ObjectOutputStream(outputStream).writeObject(priorityQueue) @@ -27,6 +33,7 @@ class PriorityQueueTest { val objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes)) val deserializedPriorityQueue = objectInputStream.readObject().asInstanceOf[PriorityQueue[Int]] + //correct sequencing is also tested here: assert(deserializedPriorityQueue.dequeueAll == elements.sorted.reverse) } } diff --git a/test/junit/scala/collection/mutable/TreeMapTest.scala b/test/junit/scala/collection/mutable/TreeMapTest.scala new file mode 100644 index 0000000000..ce79621c6f --- /dev/null +++ b/test/junit/scala/collection/mutable/TreeMapTest.scala @@ -0,0 +1,34 @@ +package scala.collection.mutable + +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +import scala.collection.mutable + +@RunWith(classOf[JUnit4]) +class TreeMapTest { + + @Test + def rangeMkString() { + + val map = mutable.TreeMap[String, String]() + + List("a", "b", "c", "d").foreach(v => map.put(v, v)) + + val range = map.range("b", "c") + + val valuesRange = range.values + val keysRange = range.keys + + assertEquals(1, valuesRange.size) + assertEquals(1, keysRange.size) + + assertEquals("b", valuesRange.mkString(",")) + assertEquals("b", keysRange.mkString(",")) + assertEquals("b -> b", range.mkString(",")) + + } + +} diff --git a/test/junit/scala/collection/mutable/TreeSetTest.scala b/test/junit/scala/collection/mutable/TreeSetTest.scala new file mode 100644 index 0000000000..50b004befc --- /dev/null +++ b/test/junit/scala/collection/mutable/TreeSetTest.scala @@ -0,0 +1,20 @@ +package scala.collection.mutable + +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +import scala.collection.mutable + + +@RunWith(classOf[JUnit4]) +class TreeSetTest { + + @Test + def rangeMkString() { + + val set = mutable.TreeSet("a", "b", "c", "d") + assertEquals("b", set.range("b", "c").mkString(",")) + } +} diff --git a/test/junit/scala/collection/mutable/WrappedArrayBuilderTest.scala b/test/junit/scala/collection/mutable/WrappedArrayBuilderTest.scala deleted file mode 100644 index 940a53abbd..0000000000 --- a/test/junit/scala/collection/mutable/WrappedArrayBuilderTest.scala +++ /dev/null @@ -1,30 +0,0 @@ -package scala.collection.mutable - -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 -import org.junit.Test - -import scala.collection.mutable -import scala.reflect.ClassTag - -@RunWith(classOf[JUnit4]) -class WrappedArrayBuilderTest { - @Test - def reusable() { - val builder = new WrappedArrayBuilder(ClassTag.Int) - val vector = Vector.range(1, 17) - val expected = new WrappedArray.ofInt(Vector.range(1, 17).toArray) - - builder ++= vector - val actual = builder.result() - assert( actual == expected ) - - builder.clear() - val expected2 = new WrappedArray.ofInt(Array[Int](100)) - builder += 100 - - // Previously created WrappedArray MUST be immutable even after `result`, `clear` and some operation are called - assert( actual == expected ) - assert( builder.result() == expected2 ) - } -} diff --git a/test/junit/scala/collection/parallel/immutable/ParRangeTest.scala b/test/junit/scala/collection/parallel/immutable/ParRangeTest.scala new file mode 100644 index 0000000000..f746fc2bf9 --- /dev/null +++ b/test/junit/scala/collection/parallel/immutable/ParRangeTest.scala @@ -0,0 +1,15 @@ +package scala.collection.parallel.immutable + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test + +@RunWith(classOf[JUnit4]) +class ParRangeTest { + + @Test + def buildParRangeString { + assert(ParRange(1, 5, 1, true).toString == "ParRange 1 to 5") + } + +} |