test/java/util/Collections/SortEmptyAndSingleton.java
Print this page
@@ -21,27 +21,32 @@
* questions.
*/
/**
* @test
- * @bug 4323074
- * @summary Basic test for newly public swap algorithm
- * @author Josh Bloch
+ * @bug 7065380
+ * @summary Tests sorting of emptyList and singletonList.
+ * @author Mike Duigou
*/
-import java.util.*;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
-public class Swap {
- static final int SIZE = 100;
+public class SortEmptyAndSingleton {
+ static final java.util.Comparator<Integer> COMPARATOR = new Comparator<Integer>() {
+ public int compare(Integer one, Integer two) {
+ return one - two;
+ }
+ };
public static void main(String[] args) throws Exception {
- List l = new ArrayList(Collections.nCopies(100, Boolean.FALSE));
- l.set(0, Boolean.TRUE);
- for (int i=0; i < SIZE-1; i++)
- Collections.swap(l, i, i+1);
+ List<Integer> empty = Collections.<Integer>emptyList();
+ Collections.sort(empty);
+ Collections.sort(empty,COMPARATOR);
- List l2 = new ArrayList(Collections.nCopies(100, Boolean.FALSE));
- l2.set(SIZE-1, Boolean.TRUE);
- if (!l.equals(l2))
- throw new RuntimeException("Wrong result");
+ // 7065380
+ List<Integer> single = Collections.<Integer>singletonList(0);
+ Collections.sort(single);
+ Collections.sort(single,COMPARATOR);
}
}