renamed random sort test to more appropriate reverse sort, and
added real random sort test git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130629 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5ae848724e
commit
8ab9293c64
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
|||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -36,6 +37,10 @@ public abstract class TestComparator extends TestObject {
|
|||
Collections.reverse(list);
|
||||
}
|
||||
|
||||
public void randomizeObjects(List list) {
|
||||
Collections.shuffle(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort object according to the given Comparator.
|
||||
*
|
||||
|
@ -66,7 +71,7 @@ public abstract class TestComparator extends TestObject {
|
|||
list2.equals(list));
|
||||
}
|
||||
|
||||
public void testRandomListSort() {
|
||||
public void testReverseListSort() {
|
||||
Comparator comparator = makeComparator();
|
||||
|
||||
List randomList = getComparableObjectsOrdered();
|
||||
|
@ -80,6 +85,27 @@ public abstract class TestComparator extends TestObject {
|
|||
|
||||
}
|
||||
|
||||
public void testRandomListSort() {
|
||||
Comparator comparator = makeComparator();
|
||||
|
||||
List randomList = getComparableObjectsOrdered();
|
||||
randomizeObjects(randomList);
|
||||
sortObjects(randomList,comparator);
|
||||
|
||||
List orderedList = getComparableObjectsOrdered();
|
||||
|
||||
/* debug
|
||||
Iterator i = randomList.iterator();
|
||||
while (i.hasNext()) {
|
||||
System.out.println(i.next());
|
||||
}
|
||||
*/
|
||||
|
||||
assertTrue("Comparator did not reorder the List correctly",
|
||||
orderedList.equals(randomList));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Nearly all Comparators should be Serializable.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue