You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by qi...@apache.org on 2009/02/11 06:30:56 UTC

svn commit: r743233 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java

Author: qiuxx
Date: Wed Feb 11 05:30:56 2009
New Revision: 743233

URL: http://svn.apache.org/viewvc?rev=743233&view=rev
Log:
Add Regression test for HARMONY-6076, ([eut][classlib][luni] - Arrays.sort(T[] a, Comparator<? super T> c) is not stable)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java?rev=743233&r1=743232&r2=743233&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java Wed Feb 11 05:30:56 2009
@@ -1308,6 +1308,50 @@
 									objectArray[counter + 1]) <= 0);
 	}
 
+    // Regression HARMONY-6076
+    public void test_sort$Ljava_lang_ObjectLjava_util_Comparator_stable() {
+        Element[] array = new Element[11];
+        array[0] = new Element(122);
+        array[1] = new Element(146);
+        array[2] = new Element(178);
+        array[3] = new Element(208);
+        array[4] = new Element(117);
+        array[5] = new Element(146);
+        array[6] = new Element(173);
+        array[7] = new Element(203);
+        array[8] = new Element(56);
+        array[9] = new Element(208);
+        array[10] = new Element(96);
+
+        Comparator<Element> comparator = new Comparator<Element>() {
+            public int compare(Element object1, Element object2) {
+                return object1.value - object2.value;
+            }
+        };
+
+        Arrays.sort(array, comparator);
+
+        for (int i = 1; i < array.length; i++) {
+            assertTrue(comparator.compare(array[i - 1], array[i]) <= 0);
+            if (comparator.compare(array[i - 1], array[i]) == 0) {
+                assertTrue(array[i - 1].index < array[i].index);
+            }
+        }
+    }
+
+    public static class Element {
+        public int value;
+
+        public int index;
+
+        private static int count = 0;
+
+        public Element(int value) {
+            this.value = value;
+            index = count++;
+        }
+    }
+
 	/**
 	 * @tests java.util.Arrays#sort(short[])
 	 */