From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5826 invoked by alias); 10 Nov 2006 17:00:00 -0000 Received: (qmail 5808 invoked by uid 22791); 10 Nov 2006 16:59:58 -0000 X-Spam-Check-By: sourceware.org Received: from outmail136025.authsmtp.co.uk (HELO outmail136025.authsmtp.co.uk) (62.13.136.25) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 10 Nov 2006 16:59:50 +0000 Received: from outmail128185.authsmtp.co.uk (outmail128185.authsmtp.co.uk [62.13.128.185]) by punt3.authsmtp.com (8.13.8/8.13.8/Kp) with ESMTP id kAAGxknf093611 for ; Fri, 10 Nov 2006 16:59:47 GMT Received: from [192.168.1.202] (host81-136-56-81.in-addr.btopenworld.com [81.136.56.81]) (authenticated bits=0) by mail.authsmtp.com (8.13.6/8.13.6/Kp) with ESMTP id kAAGxfva039578 for ; Fri, 10 Nov 2006 16:59:41 GMT Message-ID: <4554AFFE.90006@object-refinery.com> Date: Fri, 10 Nov 2006 17:00:00 -0000 From: David Gilbert User-Agent: Thunderbird 1.5.0.7 (X11/20060922) MIME-Version: 1.0 To: mauve-patches Subject: FYI: Collections.sort() - new test Content-Type: multipart/mixed; boundary="------------040006030307060800060408" X-Server-Quench: dbf2e136-70dc-11db-b4dc-001185d377ca X-AuthRoute: OCdyYgsUB1ZZRRob BmULDStKRB85DhpG AxIIMU5ALVQIUwlL IwBRKV9FNVQBW1wc QzdPCAwBEy0yBiY3 OF8Sc0cINhIfGxs5 DxUHQ1JNalouHh4B BhgOUx94cgxMfHw+ bUd8X3NdQkF8a058 XUxRCm1IPhYRHyhJ FhFYdApRdwsEeRdF aB4rBiUPNGQEYGdn RwM4emloMT8aInhZ SURVdQtLERsHRWFj TBkUMwQOTwUuQCE3 Ihc6K1kaBwAKNV8u cRppHBoePgBaFgBF AylF X-Authentic-SMTP: 61633132333134.squirrel.dmpriest.net.uk:315/Kp X-Report-SPAM: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-Virus-Status: No virus detected - but ensure you scan with your own anti-virus system! X-IsSubscribed: yes Mailing-List: contact mauve-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: mauve-patches-owner@sourceware.org X-SW-Source: 2006/txt/msg00732.txt.bz2 This is a multi-part message in MIME format. --------------040006030307060800060408 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 217 This patch (committed) adds a new test for the Collections.sort() methods: 2006-11-10 David Gilbert * gnu/testlet/java/util/Collections/sort.java: New file. Regards, Dave --------------040006030307060800060408 Content-Type: text/plain; name="diff.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="diff.txt" Content-length: 6814 Index: gnu/testlet/java/util/Collections/sort.java =================================================================== RCS file: gnu/testlet/java/util/Collections/sort.java diff -N gnu/testlet/java/util/Collections/sort.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Collections/sort.java 10 Nov 2006 16:56:55 -0000 @@ -0,0 +1,248 @@ +/* sort.java -- some checks for the sort() methods in the Collections class. + Copyright (C) 2006 David Gilbert +This file is part of Mauve. + +Mauve is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +Mauve is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Mauve; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +*/ + +// Tags: JDK1.2 + +package gnu.testlet.java.util.Collections; + +import gnu.testlet.TestHarness; +import gnu.testlet.Testlet; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +public class sort implements Testlet { + + public void test(TestHarness harness) + { + testMethod1(harness); + testMethod2(harness); + } + + public void testMethod1(TestHarness harness) + { + harness.checkPoint("(List)"); + List list = new ArrayList(); + + // sort an empty list - presumably all that can go wrong is that the code + // throws some exception due to a coding error... + boolean pass = true; + try + { + Collections.sort(list); + } + catch (Exception e) + { + pass = false; + } + harness.check(pass); + + // sort a list containing just one item + list = new ArrayList(); + list.add("A"); + Collections.sort(list); + harness.check(list.size(), 1); + harness.check(list.get(0), "A"); + + // sort a list containing two items + list = new ArrayList(); + list.add("B"); + list.add("A"); + Collections.sort(list); + harness.check(list.size(), 2); + harness.check(list.get(0), "A"); + harness.check(list.get(1), "B"); + + // sort a list containing three items + list = new ArrayList(); + list.add("B"); + list.add("A"); + list.add("C"); + Collections.sort(list); + harness.check(list.size(), 3); + harness.check(list.get(0), "A"); + harness.check(list.get(1), "B"); + harness.check(list.get(2), "C"); + + // sort a list with a null in it + pass = false; + try + { + list = new ArrayList(); + list.add("B"); + list.add("A"); + list.add(null); + Collections.sort(list); + } + catch (NullPointerException e) + { + pass = true; + } + harness.check(pass); + + // check that equal items don't change order + Object obj1 = new Integer(9500); + Object obj2 = new Integer(9600); + Object obj3 = new Integer(9500); + Object obj4 = new Integer(9600); + list = new ArrayList(); + list.add(obj1); + list.add(obj2); + list.add(obj3); + list.add(obj4); + Collections.sort(list); + harness.check(list.size(), 4); + harness.check(list.get(0), obj1); + harness.check(list.get(1), obj3); + harness.check(list.get(2), obj2); + harness.check(list.get(3), obj4); + + // try a null argument + pass = false; + try + { + Collections.sort(null); + } + catch (NullPointerException e) + { + pass = true; + } + harness.check(pass); + } + + static class MyComparator implements Comparator + { + + public int compare(Object obj0, Object obj1) { + Comparable c0 = (Comparable) obj0; + Comparable c1 = (Comparable) obj1; + return -c0.compareTo(c1); + } + + } + public void testMethod2(TestHarness harness) + { + harness.checkPoint("(List, Comparator)"); + List list = new ArrayList(); + Comparator comparator = new MyComparator(); + + // sort an empty list - presumably all that can go wrong is that the code + // throws some exception due to a coding error... + boolean pass = true; + try + { + Collections.sort(list, comparator); + } + catch (Exception e) + { + pass = false; + } + harness.check(pass); + + // sort a list containing just one item + list = new ArrayList(); + list.add("A"); + Collections.sort(list, comparator); + harness.check(list.size(), 1); + harness.check(list.get(0), "A"); + + // sort a list containing two items + list = new ArrayList(); + list.add("B"); + list.add("A"); + Collections.sort(list, comparator); + harness.check(list.size(), 2); + harness.check(list.get(0), "B"); + harness.check(list.get(1), "A"); + + // sort a list containing three items + list = new ArrayList(); + list.add("B"); + list.add("A"); + list.add("C"); + Collections.sort(list, comparator); + harness.check(list.size(), 3); + harness.check(list.get(0), "C"); + harness.check(list.get(1), "B"); + harness.check(list.get(2), "A"); + + // sort a list with a null in it + pass = false; + try + { + list = new ArrayList(); + list.add("B"); + list.add("A"); + list.add(null); + Collections.sort(list, comparator); + } + catch (NullPointerException e) + { + pass = true; + } + harness.check(pass); + + // check that equal items don't change order + Object obj1 = new Integer(9500); + Object obj2 = new Integer(9600); + Object obj3 = new Integer(9500); + Object obj4 = new Integer(9600); + list = new ArrayList(); + list.add(obj1); + list.add(obj2); + list.add(obj3); + list.add(obj4); + Collections.sort(list, comparator); + harness.check(list.size(), 4); + harness.check(list.get(0), obj2); + harness.check(list.get(1), obj4); + harness.check(list.get(2), obj1); + harness.check(list.get(3), obj3); + + // try a null argument 1 + pass = false; + try + { + Collections.sort(null, comparator); + } + catch (NullPointerException e) + { + pass = true; + } + harness.check(pass); + + // try a null argument 2 + pass = true; + try + { + Collections.sort(new ArrayList(), null); + } + catch (NullPointerException e) + { + pass = false; + } + harness.check(pass); + + } + +} \ No newline at end of file --------------040006030307060800060408--