Skip to content

Commit d38a766

Browse files
committed
Merge pull request scala#3301 from Ichoran/issue/7837
Resolves SI-7837, failure in quickSort.
2 parents cafeb34 + feebc71 commit d38a766

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/library/scala/util/Sorting.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ object Sorting {
141141
var done = false
142142
while (!done) {
143143
while (b <= c && x(b) <= v) {
144-
if (x(b) == v) {
144+
if (x(b) equiv v) {
145145
swap(a, b)
146146
a += 1
147147
}
148148
b += 1
149149
}
150150
while (c >= b && x(c) >= v) {
151-
if (x(c) == v) {
151+
if (x(c) equiv v) {
152152
swap(c, d)
153153
d -= 1
154154
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package scala.collection.mutable
2+
3+
import org.junit.runner.RunWith
4+
import org.junit.runners.JUnit4
5+
import org.junit.Test
6+
7+
/* Tests various maps by making sure they all agree on the same answers. */
8+
@RunWith(classOf[JUnit4])
9+
class ArraySortingTest {
10+
11+
class CantSortMe(val i: Int) {
12+
override def equals(a: Any) = throw new IllegalArgumentException("I cannot be equalled!")
13+
}
14+
15+
object CanOrder extends Ordering[CantSortMe] {
16+
def compare(a: CantSortMe, b: CantSortMe) = a.i compare b.i
17+
}
18+
19+
// Tests SI-7837
20+
@Test
21+
def sortByTest() {
22+
val test = Array(1,2,3,4,1,3,5,7,1,4,8,1,1,1,1)
23+
val cant = test.map(i => new CantSortMe(i))
24+
java.util.Arrays.sort(test)
25+
scala.util.Sorting.quickSort(cant)(CanOrder)
26+
assert( test(6) == 1 )
27+
assert( (test,cant).zipped.forall(_ == _.i) )
28+
}
29+
}

0 commit comments

Comments
 (0)