From 8ab9293c64f6dd519f2f8d0816b3d33053bff9bf Mon Sep 17 00:00:00 2001 From: Morgan James Delagrange Date: Fri, 1 Mar 2002 23:30:58 +0000 Subject: [PATCH] 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 --- .../comparators/TestComparator.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/test/org/apache/commons/collections/comparators/TestComparator.java b/src/test/org/apache/commons/collections/comparators/TestComparator.java index 801598531..ab9dcc375 100644 --- a/src/test/org/apache/commons/collections/comparators/TestComparator.java +++ b/src/test/org/apache/commons/collections/comparators/TestComparator.java @@ -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. */