summaryrefslogtreecommitdiff
path: root/test/junit
diff options
context:
space:
mode:
authorRex Kerr <ichoran@gmail.com>2013-12-23 15:34:18 -0800
committerRex Kerr <ichoran@gmail.com>2013-12-31 11:42:09 -0800
commitfeebc7131c669b212e6a6ff73585a879baff2c48 (patch)
treebf4522f4947ef391e2dcd6d17b2c25ead58509f2 /test/junit
parentb2bf66a4681dec76281da9469e66e0100ad2709f (diff)
downloadscala-feebc7131c669b212e6a6ff73585a879baff2c48.tar.gz
scala-feebc7131c669b212e6a6ff73585a879baff2c48.tar.bz2
scala-feebc7131c669b212e6a6ff73585a879baff2c48.zip
SI-7837 quickSort, along with Ordering[K], may result in stackoverflow because the code uses '==' instead of 'equiv'
== instead of equiv (from Ordering) was used by mistake. Fixed. Also created a test to make sure that == is not used by throwing an exception if it is (as suggested by Jason).
Diffstat (limited to 'test/junit')
-rw-r--r--test/junit/scala/collection/ArraySortingTest.scala29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/junit/scala/collection/ArraySortingTest.scala b/test/junit/scala/collection/ArraySortingTest.scala
new file mode 100644
index 0000000000..4e54b39ce7
--- /dev/null
+++ b/test/junit/scala/collection/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) )
+ }
+}