From 159ca839b9d63da6c402731342d827f227219323 Mon Sep 17 00:00:00 2001 From: Antoine Gourlay Date: Mon, 29 Sep 2014 10:07:40 +0200 Subject: Better ant / junit interaction Currently junit test sources are always rebuilt, that's wasteful. The second dependency on the junit task is there so that the first can be skipped if sources haven't changed. Also normalize package names versus location in the `test/junit` folder: ant isn't very clever when it comes to selectively recompiling tests, so now editing a test will only cause that one to be recompiled (instead of ~13 files every time). This makes TDD with junit even faster. --- test/junit/scala/collection/ArraySortingTest.scala | 29 ----- test/junit/scala/collection/NumericRangeTest.scala | 140 --------------------- test/junit/scala/collection/PagedSeq.scala | 16 --- .../junit/scala/collection/PriorityQueueTest.scala | 32 ----- test/junit/scala/collection/QueueTest.scala | 28 ----- test/junit/scala/collection/StreamTest.scala | 18 --- test/junit/scala/collection/VectorTest.scala | 51 -------- .../scala/collection/immutable/PagedSeqTest.scala | 16 +++ .../scala/collection/immutable/QueueTest.scala | 28 +++++ .../immutable/RangeConsistencyTest.scala | 140 +++++++++++++++++++++ .../scala/collection/immutable/StreamTest.scala | 18 +++ .../collection/mutable/ArraySortingTest.scala | 29 +++++ .../collection/mutable/PriorityQueueTest.scala | 32 +++++ .../scala/collection/mutable/VectorTest.scala | 51 ++++++++ test/junit/scala/math/NumericTest.scala | 2 +- test/junit/scala/reflect/internal/ScopeTest.scala | 2 +- test/junit/scala/tools/nsc/SampleTest.scala | 1 - test/junit/scala/util/SpecVersionTest.scala | 57 +++++++++ test/junit/scala/util/matching/CharRegexTest.scala | 58 +++++++++ .../scala/util/matching/regextract-char.scala | 58 --------- test/junit/scala/util/t7265.scala | 59 --------- 21 files changed, 431 insertions(+), 434 deletions(-) delete mode 100644 test/junit/scala/collection/ArraySortingTest.scala delete mode 100644 test/junit/scala/collection/NumericRangeTest.scala delete mode 100644 test/junit/scala/collection/PagedSeq.scala delete mode 100644 test/junit/scala/collection/PriorityQueueTest.scala delete mode 100644 test/junit/scala/collection/QueueTest.scala delete mode 100644 test/junit/scala/collection/StreamTest.scala delete mode 100644 test/junit/scala/collection/VectorTest.scala create mode 100644 test/junit/scala/collection/immutable/PagedSeqTest.scala create mode 100644 test/junit/scala/collection/immutable/QueueTest.scala create mode 100644 test/junit/scala/collection/immutable/RangeConsistencyTest.scala create mode 100644 test/junit/scala/collection/immutable/StreamTest.scala create mode 100644 test/junit/scala/collection/mutable/ArraySortingTest.scala create mode 100644 test/junit/scala/collection/mutable/PriorityQueueTest.scala create mode 100644 test/junit/scala/collection/mutable/VectorTest.scala create mode 100644 test/junit/scala/util/SpecVersionTest.scala create mode 100644 test/junit/scala/util/matching/CharRegexTest.scala delete mode 100644 test/junit/scala/util/matching/regextract-char.scala delete mode 100644 test/junit/scala/util/t7265.scala (limited to 'test') diff --git a/test/junit/scala/collection/ArraySortingTest.scala b/test/junit/scala/collection/ArraySortingTest.scala deleted file mode 100644 index 4e54b39ce7..0000000000 --- a/test/junit/scala/collection/ArraySortingTest.scala +++ /dev/null @@ -1,29 +0,0 @@ -package scala.collection.mutable - -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 ArraySortingTest { - - class CantSortMe(val i: Int) { - override def equals(a: Any) = throw new IllegalArgumentException("I cannot be equalled!") - } - - object CanOrder extends Ordering[CantSortMe] { - def compare(a: CantSortMe, b: CantSortMe) = a.i compare b.i - } - - // Tests SI-7837 - @Test - def sortByTest() { - val test = Array(1,2,3,4,1,3,5,7,1,4,8,1,1,1,1) - val cant = test.map(i => new CantSortMe(i)) - java.util.Arrays.sort(test) - scala.util.Sorting.quickSort(cant)(CanOrder) - assert( test(6) == 1 ) - assert( (test,cant).zipped.forall(_ == _.i) ) - } -} diff --git a/test/junit/scala/collection/NumericRangeTest.scala b/test/junit/scala/collection/NumericRangeTest.scala deleted file mode 100644 index 3980c31577..0000000000 --- a/test/junit/scala/collection/NumericRangeTest.scala +++ /dev/null @@ -1,140 +0,0 @@ -package scala.collection.immutable - -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 -import org.junit.Test -import scala.math._ -import scala.util._ - -/* Tests various ranges by making sure they all agree on the same answers. */ -@RunWith(classOf[JUnit4]) -class RangeConsistencyTest { - def r2nr[T: Integral]( - r: Range, puff: T, stride: T, check: (T,T) => Boolean, bi: T => BigInt - ): List[(BigInt,Try[Int])] = { - val num = implicitly[Integral[T]] - import num._ - val one = num.one - - if (!check(puff, fromInt(r.start))) return Nil - val start = puff * fromInt(r.start) - val sp1 = start + one - val sn1 = start - one - - if (!check(puff, fromInt(r.end))) return Nil - val end = puff * fromInt(r.end) - val ep1 = end + one - val en1 = end - one - - if (!check(stride, fromInt(r.step))) return Nil - val step = stride * fromInt(r.step) - - def NR(s: T, e: T, i: T) = { - val delta = (bi(e) - bi(s)).abs - (if (r.isInclusive) 0 else 1) - val n = if (r.length == 0) BigInt(0) else delta / bi(i).abs + 1 - if (r.isInclusive) { - (n, Try(NumericRange.inclusive(s,e,i).length)) - } - else { - (n, Try(NumericRange(s,e,i).length)) - } - } - - List(NR(start, end, step)) ::: - (if (sn1 < start) List(NR(sn1, end, step)) else Nil) ::: - (if (start < sp1) List(NR(sp1, end, step)) else Nil) ::: - (if (en1 < end) List(NR(start, en1, step)) else Nil) ::: - (if (end < ep1) List(NR(start, ep1, step)) else Nil) - } - - // Motivated by SI-4370: Wrong result for Long.MinValue to Long.MaxValue by Int.MaxValue - @Test - def rangeChurnTest() { - val rn = new Random(4370) - for (i <- 0 to 10000) { control.Breaks.breakable { - val start = rn.nextInt - val end = rn.nextInt - val step = rn.nextInt(4) match { - case 0 => 1 - case 1 => -1 - case 2 => (rn.nextInt(11)+2)*(2*rn.nextInt(2)+1) - case 3 => var x = rn.nextInt; while (x==0) x = rn.nextInt; x - } - val r = if (rn.nextBoolean) Range.inclusive(start, end, step) else Range(start, end, step) - - try { r.length } - catch { case iae: IllegalArgumentException => control.Breaks.break } - - val lpuff = rn.nextInt(4) match { - case 0 => 1L - case 1 => rn.nextInt(11)+2L - case 2 => 1L << rn.nextInt(60) - case 3 => math.max(1L, math.abs(rn.nextLong)) - } - val lstride = rn.nextInt(4) match { - case 0 => lpuff - case 1 => 1L - case 2 => 1L << rn.nextInt(60) - case 3 => math.max(1L, math.abs(rn.nextLong)) - } - val lr = r2nr[Long]( - r, lpuff, lstride, - (a,b) => { val x = BigInt(a)*BigInt(b); x.isValidLong }, - x => BigInt(x) - ) - - lr.foreach{ case (n,t) => assert( - t match { - case Failure(_) => n > Int.MaxValue - case Success(m) => n == m - }, - (r.start, r.end, r.step, r.isInclusive, lpuff, lstride, n, t) - )} - - val bipuff = rn.nextInt(3) match { - case 0 => BigInt(1) - case 1 => BigInt(rn.nextLong) + Long.MaxValue + 2 - case 2 => BigInt("1" + "0"*(rn.nextInt(100)+1)) - } - val bistride = rn.nextInt(3) match { - case 0 => bipuff - case 1 => BigInt(1) - case 2 => BigInt("1" + "0"*(rn.nextInt(100)+1)) - } - val bir = r2nr[BigInt](r, bipuff, bistride, (a,b) => true, identity) - - bir.foreach{ case (n,t) => assert( - t match { - case Failure(_) => n > Int.MaxValue - case Success(m) => n == m - }, - (r.start, r.end, r.step, r.isInclusive, bipuff, bistride, n, t) - )} - }} - } - - @Test - def testSI4370() { assert{ - Try((Long.MinValue to Long.MaxValue by Int.MaxValue).length) match { - case Failure(iae: IllegalArgumentException) => true - case _ => false - } - }} - - @Test - def testSI6736() { - // These operations on overfull ranges should all succeed. - assert( (0 to Int.MaxValue).contains(4) ) - assert( !((Int.MinValue to 0).contains(4)) ) - assert( (Int.MinValue to 0).last == 0 ) - assert( (Int.MinValue until 5).last == 4 ) - assert( (-7 to -99 by -4).last == -99 && (-7 until -99 by -4).last == -95 ) - assert( (Int.MinValue to 5) == (Int.MinValue until 6) ) - assert( (-3 to Int.MaxValue).drop(4).length == Int.MaxValue ) - assert( (-3 to Int.MaxValue).take(1234) == (-3 to 1230) ) - assert( (-3 to Int.MaxValue).dropRight(4).length == Int.MaxValue ) - assert( (-3 to Int.MaxValue).takeRight(1234).length == 1234 ) - assert( (-3 to Int.MaxValue).dropWhile(_ <= 0).length == Int.MaxValue ) - assert( (-3 to Int.MaxValue).span(_ <= 0) match { case (a,b) => a.length == 4 && b.length == Int.MaxValue } ) - } -} diff --git a/test/junit/scala/collection/PagedSeq.scala b/test/junit/scala/collection/PagedSeq.scala deleted file mode 100644 index 5f83cf6f31..0000000000 --- a/test/junit/scala/collection/PagedSeq.scala +++ /dev/null @@ -1,16 +0,0 @@ -package scala.collection.immutable - -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 -import org.junit.Test -import org.junit.Assert._ - -/* Test for SI-6615 */ -@RunWith(classOf[JUnit4]) -class PagedSeqTest { - @Test - def rovingDoesNotNPE(): Unit = { - // should not NPE, and should equal the given Seq - assertEquals(Seq('a'), PagedSeq.fromStrings(List.fill(5000)("a")).slice(4096, 4097)) - } -} diff --git a/test/junit/scala/collection/PriorityQueueTest.scala b/test/junit/scala/collection/PriorityQueueTest.scala deleted file mode 100644 index a14f1bf4c8..0000000000 --- a/test/junit/scala/collection/PriorityQueueTest.scala +++ /dev/null @@ -1,32 +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 java.io.{ObjectInputStream, ByteArrayInputStream, ByteArrayOutputStream, ObjectOutputStream} - -@RunWith(classOf[JUnit4]) -/* Test for SI-7568 */ -class PriorityQueueTest { - val priorityQueue = new mutable.PriorityQueue[Int]() - val elements = List.fill(1000)(scala.util.Random.nextInt(Int.MaxValue)) - priorityQueue.enqueue(elements :_*) - - @Test - def canSerialize() { - val outputStream = new ByteArrayOutputStream() - new ObjectOutputStream(outputStream).writeObject(priorityQueue) - } - - @Test - def maintainsStateWhenDeserialized() { - val outputStream = new ByteArrayOutputStream() - new ObjectOutputStream(outputStream).writeObject(priorityQueue) - val bytes = outputStream.toByteArray - - val objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes)) - val deserializedPriorityQueue = objectInputStream.readObject().asInstanceOf[PriorityQueue[Int]] - assert(deserializedPriorityQueue.dequeueAll == elements.sorted.reverse) - } -} diff --git a/test/junit/scala/collection/QueueTest.scala b/test/junit/scala/collection/QueueTest.scala deleted file mode 100644 index 9a40d8fc90..0000000000 --- a/test/junit/scala/collection/QueueTest.scala +++ /dev/null @@ -1,28 +0,0 @@ -package scala.collection.immutable - -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 -import org.junit.Test - -@RunWith(classOf[JUnit4]) -/* Tests for collection.immutable.Queue */ -class QueueTest { - val emptyQueue = Queue.empty[Int] - val oneAdded = emptyQueue.enqueue(1) - val threeAdded = emptyQueue.enqueue(1 to 3) - - @Test - def dequeueOptionOnEmpty() { - assert( emptyQueue.dequeueOption == None ) - } - - @Test - def dequeueOptionOneAdded() { - assert( oneAdded.dequeueOption == Some((1,emptyQueue)) ) - } - - @Test - def dequeueOptionThreeAdded() { - assert( threeAdded.dequeueOption == Some((1,Queue(2 to 3:_*))) ) - } -} diff --git a/test/junit/scala/collection/StreamTest.scala b/test/junit/scala/collection/StreamTest.scala deleted file mode 100644 index 6dc1c79a48..0000000000 --- a/test/junit/scala/collection/StreamTest.scala +++ /dev/null @@ -1,18 +0,0 @@ -package scala.collection.immutable - -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 -import org.junit.Test -import org.junit.Assert._ - -@RunWith(classOf[JUnit4]) -class StreamTest { - - @Test - def t6727_and_t6440(): 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)) - } -} diff --git a/test/junit/scala/collection/VectorTest.scala b/test/junit/scala/collection/VectorTest.scala deleted file mode 100644 index e9c4d44a72..0000000000 --- a/test/junit/scala/collection/VectorTest.scala +++ /dev/null @@ -1,51 +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]) -/* Test for SI-8014 and ++ in general */ -class VectorTest { - val noVec = Vector.empty[Int] - val smallVec = Vector.range(0,3) - val bigVec = Vector.range(0,64) - val smsm = Vector.tabulate(2 * smallVec.length)(i => (i % smallVec.length)) - val smbig = Vector.tabulate(smallVec.length + bigVec.length)(i => - if (i < smallVec.length) i else i - smallVec.length - ) - val bigsm = Vector.tabulate(smallVec.length + bigVec.length)(i => - if (i < bigVec.length) i else i - bigVec.length - ) - val bigbig = Vector.tabulate(2 * bigVec.length)(i => (i % bigVec.length)) - - - val vecs = List(noVec, smallVec, bigVec) - val ans = List( - vecs, - List(smallVec, smsm, smbig), - List(bigVec, bigsm, bigbig) - ) - - @Test - def vectorCat() { - val cats = vecs.map(a => vecs.map(a ++ _)) - assert( cats == ans ) - } - - @Test - def iteratorCat() { - def its = vecs.map(_.toList.toIterator) - val cats = vecs.map(a => its.map(a ++ _)) - println(cats) - assert( cats == ans ) - } - - @Test - def arrayCat() { - val ars = vecs.map(_.toArray) - val cats = vecs.map(a => ars.map(a ++ _)) - assert( cats == ans ) - } -} diff --git a/test/junit/scala/collection/immutable/PagedSeqTest.scala b/test/junit/scala/collection/immutable/PagedSeqTest.scala new file mode 100644 index 0000000000..5f83cf6f31 --- /dev/null +++ b/test/junit/scala/collection/immutable/PagedSeqTest.scala @@ -0,0 +1,16 @@ +package scala.collection.immutable + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import org.junit.Assert._ + +/* Test for SI-6615 */ +@RunWith(classOf[JUnit4]) +class PagedSeqTest { + @Test + def rovingDoesNotNPE(): Unit = { + // should not NPE, and should equal the given Seq + assertEquals(Seq('a'), PagedSeq.fromStrings(List.fill(5000)("a")).slice(4096, 4097)) + } +} diff --git a/test/junit/scala/collection/immutable/QueueTest.scala b/test/junit/scala/collection/immutable/QueueTest.scala new file mode 100644 index 0000000000..9a40d8fc90 --- /dev/null +++ b/test/junit/scala/collection/immutable/QueueTest.scala @@ -0,0 +1,28 @@ +package scala.collection.immutable + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test + +@RunWith(classOf[JUnit4]) +/* Tests for collection.immutable.Queue */ +class QueueTest { + val emptyQueue = Queue.empty[Int] + val oneAdded = emptyQueue.enqueue(1) + val threeAdded = emptyQueue.enqueue(1 to 3) + + @Test + def dequeueOptionOnEmpty() { + assert( emptyQueue.dequeueOption == None ) + } + + @Test + def dequeueOptionOneAdded() { + assert( oneAdded.dequeueOption == Some((1,emptyQueue)) ) + } + + @Test + def dequeueOptionThreeAdded() { + assert( threeAdded.dequeueOption == Some((1,Queue(2 to 3:_*))) ) + } +} diff --git a/test/junit/scala/collection/immutable/RangeConsistencyTest.scala b/test/junit/scala/collection/immutable/RangeConsistencyTest.scala new file mode 100644 index 0000000000..3980c31577 --- /dev/null +++ b/test/junit/scala/collection/immutable/RangeConsistencyTest.scala @@ -0,0 +1,140 @@ +package scala.collection.immutable + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import scala.math._ +import scala.util._ + +/* Tests various ranges by making sure they all agree on the same answers. */ +@RunWith(classOf[JUnit4]) +class RangeConsistencyTest { + def r2nr[T: Integral]( + r: Range, puff: T, stride: T, check: (T,T) => Boolean, bi: T => BigInt + ): List[(BigInt,Try[Int])] = { + val num = implicitly[Integral[T]] + import num._ + val one = num.one + + if (!check(puff, fromInt(r.start))) return Nil + val start = puff * fromInt(r.start) + val sp1 = start + one + val sn1 = start - one + + if (!check(puff, fromInt(r.end))) return Nil + val end = puff * fromInt(r.end) + val ep1 = end + one + val en1 = end - one + + if (!check(stride, fromInt(r.step))) return Nil + val step = stride * fromInt(r.step) + + def NR(s: T, e: T, i: T) = { + val delta = (bi(e) - bi(s)).abs - (if (r.isInclusive) 0 else 1) + val n = if (r.length == 0) BigInt(0) else delta / bi(i).abs + 1 + if (r.isInclusive) { + (n, Try(NumericRange.inclusive(s,e,i).length)) + } + else { + (n, Try(NumericRange(s,e,i).length)) + } + } + + List(NR(start, end, step)) ::: + (if (sn1 < start) List(NR(sn1, end, step)) else Nil) ::: + (if (start < sp1) List(NR(sp1, end, step)) else Nil) ::: + (if (en1 < end) List(NR(start, en1, step)) else Nil) ::: + (if (end < ep1) List(NR(start, ep1, step)) else Nil) + } + + // Motivated by SI-4370: Wrong result for Long.MinValue to Long.MaxValue by Int.MaxValue + @Test + def rangeChurnTest() { + val rn = new Random(4370) + for (i <- 0 to 10000) { control.Breaks.breakable { + val start = rn.nextInt + val end = rn.nextInt + val step = rn.nextInt(4) match { + case 0 => 1 + case 1 => -1 + case 2 => (rn.nextInt(11)+2)*(2*rn.nextInt(2)+1) + case 3 => var x = rn.nextInt; while (x==0) x = rn.nextInt; x + } + val r = if (rn.nextBoolean) Range.inclusive(start, end, step) else Range(start, end, step) + + try { r.length } + catch { case iae: IllegalArgumentException => control.Breaks.break } + + val lpuff = rn.nextInt(4) match { + case 0 => 1L + case 1 => rn.nextInt(11)+2L + case 2 => 1L << rn.nextInt(60) + case 3 => math.max(1L, math.abs(rn.nextLong)) + } + val lstride = rn.nextInt(4) match { + case 0 => lpuff + case 1 => 1L + case 2 => 1L << rn.nextInt(60) + case 3 => math.max(1L, math.abs(rn.nextLong)) + } + val lr = r2nr[Long]( + r, lpuff, lstride, + (a,b) => { val x = BigInt(a)*BigInt(b); x.isValidLong }, + x => BigInt(x) + ) + + lr.foreach{ case (n,t) => assert( + t match { + case Failure(_) => n > Int.MaxValue + case Success(m) => n == m + }, + (r.start, r.end, r.step, r.isInclusive, lpuff, lstride, n, t) + )} + + val bipuff = rn.nextInt(3) match { + case 0 => BigInt(1) + case 1 => BigInt(rn.nextLong) + Long.MaxValue + 2 + case 2 => BigInt("1" + "0"*(rn.nextInt(100)+1)) + } + val bistride = rn.nextInt(3) match { + case 0 => bipuff + case 1 => BigInt(1) + case 2 => BigInt("1" + "0"*(rn.nextInt(100)+1)) + } + val bir = r2nr[BigInt](r, bipuff, bistride, (a,b) => true, identity) + + bir.foreach{ case (n,t) => assert( + t match { + case Failure(_) => n > Int.MaxValue + case Success(m) => n == m + }, + (r.start, r.end, r.step, r.isInclusive, bipuff, bistride, n, t) + )} + }} + } + + @Test + def testSI4370() { assert{ + Try((Long.MinValue to Long.MaxValue by Int.MaxValue).length) match { + case Failure(iae: IllegalArgumentException) => true + case _ => false + } + }} + + @Test + def testSI6736() { + // These operations on overfull ranges should all succeed. + assert( (0 to Int.MaxValue).contains(4) ) + assert( !((Int.MinValue to 0).contains(4)) ) + assert( (Int.MinValue to 0).last == 0 ) + assert( (Int.MinValue until 5).last == 4 ) + assert( (-7 to -99 by -4).last == -99 && (-7 until -99 by -4).last == -95 ) + assert( (Int.MinValue to 5) == (Int.MinValue until 6) ) + assert( (-3 to Int.MaxValue).drop(4).length == Int.MaxValue ) + assert( (-3 to Int.MaxValue).take(1234) == (-3 to 1230) ) + assert( (-3 to Int.MaxValue).dropRight(4).length == Int.MaxValue ) + assert( (-3 to Int.MaxValue).takeRight(1234).length == 1234 ) + assert( (-3 to Int.MaxValue).dropWhile(_ <= 0).length == Int.MaxValue ) + assert( (-3 to Int.MaxValue).span(_ <= 0) match { case (a,b) => a.length == 4 && b.length == Int.MaxValue } ) + } +} diff --git a/test/junit/scala/collection/immutable/StreamTest.scala b/test/junit/scala/collection/immutable/StreamTest.scala new file mode 100644 index 0000000000..6dc1c79a48 --- /dev/null +++ b/test/junit/scala/collection/immutable/StreamTest.scala @@ -0,0 +1,18 @@ +package scala.collection.immutable + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import org.junit.Assert._ + +@RunWith(classOf[JUnit4]) +class StreamTest { + + @Test + def t6727_and_t6440(): 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)) + } +} diff --git a/test/junit/scala/collection/mutable/ArraySortingTest.scala b/test/junit/scala/collection/mutable/ArraySortingTest.scala new file mode 100644 index 0000000000..4e54b39ce7 --- /dev/null +++ b/test/junit/scala/collection/mutable/ArraySortingTest.scala @@ -0,0 +1,29 @@ +package scala.collection.mutable + +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 ArraySortingTest { + + class CantSortMe(val i: Int) { + override def equals(a: Any) = throw new IllegalArgumentException("I cannot be equalled!") + } + + object CanOrder extends Ordering[CantSortMe] { + def compare(a: CantSortMe, b: CantSortMe) = a.i compare b.i + } + + // Tests SI-7837 + @Test + def sortByTest() { + val test = Array(1,2,3,4,1,3,5,7,1,4,8,1,1,1,1) + val cant = test.map(i => new CantSortMe(i)) + java.util.Arrays.sort(test) + scala.util.Sorting.quickSort(cant)(CanOrder) + assert( test(6) == 1 ) + assert( (test,cant).zipped.forall(_ == _.i) ) + } +} diff --git a/test/junit/scala/collection/mutable/PriorityQueueTest.scala b/test/junit/scala/collection/mutable/PriorityQueueTest.scala new file mode 100644 index 0000000000..a14f1bf4c8 --- /dev/null +++ b/test/junit/scala/collection/mutable/PriorityQueueTest.scala @@ -0,0 +1,32 @@ +package scala.collection.mutable + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import scala.collection.mutable +import java.io.{ObjectInputStream, ByteArrayInputStream, ByteArrayOutputStream, ObjectOutputStream} + +@RunWith(classOf[JUnit4]) +/* Test for SI-7568 */ +class PriorityQueueTest { + val priorityQueue = new mutable.PriorityQueue[Int]() + val elements = List.fill(1000)(scala.util.Random.nextInt(Int.MaxValue)) + priorityQueue.enqueue(elements :_*) + + @Test + def canSerialize() { + val outputStream = new ByteArrayOutputStream() + new ObjectOutputStream(outputStream).writeObject(priorityQueue) + } + + @Test + def maintainsStateWhenDeserialized() { + val outputStream = new ByteArrayOutputStream() + new ObjectOutputStream(outputStream).writeObject(priorityQueue) + val bytes = outputStream.toByteArray + + val objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes)) + val deserializedPriorityQueue = objectInputStream.readObject().asInstanceOf[PriorityQueue[Int]] + assert(deserializedPriorityQueue.dequeueAll == elements.sorted.reverse) + } +} diff --git a/test/junit/scala/collection/mutable/VectorTest.scala b/test/junit/scala/collection/mutable/VectorTest.scala new file mode 100644 index 0000000000..e9c4d44a72 --- /dev/null +++ b/test/junit/scala/collection/mutable/VectorTest.scala @@ -0,0 +1,51 @@ +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]) +/* Test for SI-8014 and ++ in general */ +class VectorTest { + val noVec = Vector.empty[Int] + val smallVec = Vector.range(0,3) + val bigVec = Vector.range(0,64) + val smsm = Vector.tabulate(2 * smallVec.length)(i => (i % smallVec.length)) + val smbig = Vector.tabulate(smallVec.length + bigVec.length)(i => + if (i < smallVec.length) i else i - smallVec.length + ) + val bigsm = Vector.tabulate(smallVec.length + bigVec.length)(i => + if (i < bigVec.length) i else i - bigVec.length + ) + val bigbig = Vector.tabulate(2 * bigVec.length)(i => (i % bigVec.length)) + + + val vecs = List(noVec, smallVec, bigVec) + val ans = List( + vecs, + List(smallVec, smsm, smbig), + List(bigVec, bigsm, bigbig) + ) + + @Test + def vectorCat() { + val cats = vecs.map(a => vecs.map(a ++ _)) + assert( cats == ans ) + } + + @Test + def iteratorCat() { + def its = vecs.map(_.toList.toIterator) + val cats = vecs.map(a => its.map(a ++ _)) + println(cats) + assert( cats == ans ) + } + + @Test + def arrayCat() { + val ars = vecs.map(_.toArray) + val cats = vecs.map(a => ars.map(a ++ _)) + assert( cats == ans ) + } +} diff --git a/test/junit/scala/math/NumericTest.scala b/test/junit/scala/math/NumericTest.scala index 4f0657f471..9bf7d4f1e4 100644 --- a/test/junit/scala/math/NumericTest.scala +++ b/test/junit/scala/math/NumericTest.scala @@ -1,4 +1,4 @@ - +package scala.math import org.junit.Assert._ import org.junit.Test diff --git a/test/junit/scala/reflect/internal/ScopeTest.scala b/test/junit/scala/reflect/internal/ScopeTest.scala index 5166620189..1ab24facac 100644 --- a/test/junit/scala/reflect/internal/ScopeTest.scala +++ b/test/junit/scala/reflect/internal/ScopeTest.scala @@ -1,4 +1,4 @@ -package symtab +package scala.reflect.internal import scala.tools.nsc.symtab diff --git a/test/junit/scala/tools/nsc/SampleTest.scala b/test/junit/scala/tools/nsc/SampleTest.scala index 8e026da1ea..810c88ef9d 100644 --- a/test/junit/scala/tools/nsc/SampleTest.scala +++ b/test/junit/scala/tools/nsc/SampleTest.scala @@ -1,5 +1,4 @@ package scala.tools.nsc -package test import org.junit.Assert._ import org.junit.Test diff --git a/test/junit/scala/util/SpecVersionTest.scala b/test/junit/scala/util/SpecVersionTest.scala new file mode 100644 index 0000000000..e3e7a978f2 --- /dev/null +++ b/test/junit/scala/util/SpecVersionTest.scala @@ -0,0 +1,57 @@ + +package scala.util + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +/** The java version property uses the spec version + * and must work for all "major.minor" and fail otherwise. + */ +@RunWith(classOf[JUnit4]) +class SpecVersionTest { + val sut = new PropertiesTrait { + override def javaSpecVersion = "1.7" + + override protected def pickJarBasedOn: Class[_] = ??? + override protected def propCategory: String = "test" + + // override because of vals like releaseVersion + override lazy val scalaProps = new java.util.Properties + } + + // SI-7265 + @Test + def comparesCorrectly(): Unit = { + assert(sut isJavaAtLeast "1.5") + assert(sut isJavaAtLeast "1.6") + assert(sut isJavaAtLeast "1.7") + assert(!(sut isJavaAtLeast "1.8")) + assert(!(sut isJavaAtLeast "1.71")) + } + @Test(expected = classOf[NumberFormatException]) + def badVersion(): Unit = { + sut isJavaAtLeast "1.a" + } + @Test(expected = classOf[NumberFormatException]) + def missingVersion(): Unit = { + sut isJavaAtLeast "1" + } + @Test(expected = classOf[NumberFormatException]) + def noVersion(): Unit = { + sut isJavaAtLeast "" + } + @Test(expected = classOf[NumberFormatException]) + def dotOnly(): Unit = { + sut isJavaAtLeast "." + } + @Test(expected = classOf[NumberFormatException]) + def leadingDot(): Unit = { + sut isJavaAtLeast ".5" + } + @Test(expected = classOf[NumberFormatException]) + def notASpec(): Unit = { + sut isJavaAtLeast "1.7.1" + } +} diff --git a/test/junit/scala/util/matching/CharRegexTest.scala b/test/junit/scala/util/matching/CharRegexTest.scala new file mode 100644 index 0000000000..50fdcd9d46 --- /dev/null +++ b/test/junit/scala/util/matching/CharRegexTest.scala @@ -0,0 +1,58 @@ + +package scala.util.matching + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +import PartialFunction._ + +/** Regex can match a Char. + * If the pattern includes a group, + * always return a single char. + */ +@RunWith(classOf[JUnit4]) +class CharRegexTest { + implicit class Averrable(val b: Boolean) /*extends AnyVal*/ { + def yes = assert(b) + def no = assert(!b) + } + val c: Char = 'c' // "cat"(0) + val d: Char = 'D' // "Dog"(0) + + @Test def comparesGroupCorrectly(): Unit = { + val r = """(\p{Lower})""".r + cond(c) { case r(x) => true } .yes + cond(c) { case r(_) => true } .yes + cond(c) { case r(_*) => true } .yes + cond(c) { case r() => true } .no + + cond(d) { case r(x) => true } .no + cond(d) { case r(_) => true } .no + cond(d) { case r(_*) => true } .no + cond(d) { case r() => true } .no + } + + @Test def comparesNoGroupCorrectly(): Unit = { + val rnc = """\p{Lower}""".r + cond(c) { case rnc(x) => true } .no + cond(c) { case rnc(_) => true } .no + cond(c) { case rnc(_*) => true } .yes + cond(c) { case rnc() => true } .yes + + cond(d) { case rnc(x) => true } .no + cond(d) { case rnc(_) => true } .no + cond(d) { case rnc(_*) => true } .no + cond(d) { case rnc() => true } .no + } + + @Test(expected = classOf[MatchError]) + def failCorrectly(): Unit = { + val headAndTail = """(\p{Lower})([a-z]+)""".r + val n = "cat"(0) match { + case headAndTail(ht @ _*) => ht.size + } + assert(false, s"Match size $n") + } +} diff --git a/test/junit/scala/util/matching/regextract-char.scala b/test/junit/scala/util/matching/regextract-char.scala deleted file mode 100644 index 50fdcd9d46..0000000000 --- a/test/junit/scala/util/matching/regextract-char.scala +++ /dev/null @@ -1,58 +0,0 @@ - -package scala.util.matching - -import org.junit.Assert._ -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 - -import PartialFunction._ - -/** Regex can match a Char. - * If the pattern includes a group, - * always return a single char. - */ -@RunWith(classOf[JUnit4]) -class CharRegexTest { - implicit class Averrable(val b: Boolean) /*extends AnyVal*/ { - def yes = assert(b) - def no = assert(!b) - } - val c: Char = 'c' // "cat"(0) - val d: Char = 'D' // "Dog"(0) - - @Test def comparesGroupCorrectly(): Unit = { - val r = """(\p{Lower})""".r - cond(c) { case r(x) => true } .yes - cond(c) { case r(_) => true } .yes - cond(c) { case r(_*) => true } .yes - cond(c) { case r() => true } .no - - cond(d) { case r(x) => true } .no - cond(d) { case r(_) => true } .no - cond(d) { case r(_*) => true } .no - cond(d) { case r() => true } .no - } - - @Test def comparesNoGroupCorrectly(): Unit = { - val rnc = """\p{Lower}""".r - cond(c) { case rnc(x) => true } .no - cond(c) { case rnc(_) => true } .no - cond(c) { case rnc(_*) => true } .yes - cond(c) { case rnc() => true } .yes - - cond(d) { case rnc(x) => true } .no - cond(d) { case rnc(_) => true } .no - cond(d) { case rnc(_*) => true } .no - cond(d) { case rnc() => true } .no - } - - @Test(expected = classOf[MatchError]) - def failCorrectly(): Unit = { - val headAndTail = """(\p{Lower})([a-z]+)""".r - val n = "cat"(0) match { - case headAndTail(ht @ _*) => ht.size - } - assert(false, s"Match size $n") - } -} diff --git a/test/junit/scala/util/t7265.scala b/test/junit/scala/util/t7265.scala deleted file mode 100644 index 71f085d21d..0000000000 --- a/test/junit/scala/util/t7265.scala +++ /dev/null @@ -1,59 +0,0 @@ - -package scala.util -package test - -import org.junit.Assert._ -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 - -import scala.util.PropertiesTrait - -/** The java version property uses the spec version - * and must work for all "major.minor" and fail otherwise. - */ -@RunWith(classOf[JUnit4]) -class SpecVersionTest { - val sut = new PropertiesTrait { - override def javaSpecVersion = "1.7" - - override protected def pickJarBasedOn: Class[_] = ??? - override protected def propCategory: String = "test" - - // override because of vals like releaseVersion - override lazy val scalaProps = new java.util.Properties - } - - @Test - def comparesCorrectly(): Unit = { - assert(sut isJavaAtLeast "1.5") - assert(sut isJavaAtLeast "1.6") - assert(sut isJavaAtLeast "1.7") - assert(!(sut isJavaAtLeast "1.8")) - assert(!(sut isJavaAtLeast "1.71")) - } - @Test(expected = classOf[NumberFormatException]) - def badVersion(): Unit = { - sut isJavaAtLeast "1.a" - } - @Test(expected = classOf[NumberFormatException]) - def missingVersion(): Unit = { - sut isJavaAtLeast "1" - } - @Test(expected = classOf[NumberFormatException]) - def noVersion(): Unit = { - sut isJavaAtLeast "" - } - @Test(expected = classOf[NumberFormatException]) - def dotOnly(): Unit = { - sut isJavaAtLeast "." - } - @Test(expected = classOf[NumberFormatException]) - def leadingDot(): Unit = { - sut isJavaAtLeast ".5" - } - @Test(expected = classOf[NumberFormatException]) - def notASpec(): Unit = { - sut isJavaAtLeast "1.7.1" - } -} -- cgit v1.2.3