This is the mail archive of the
mauve-patches@sources.redhat.com
mailing list for the Mauve project.
java.util.Arrays
- From: David Gilbert <david dot gilbert at object-refinery dot com>
- To: mauve-patches at sources dot redhat dot com
- Cc: mark at klomp dot org
- Date: Fri, 27 Aug 2004 17:25:27 +0100
- Subject: java.util.Arrays
For the java.util.Arrays class, I've attached three new tests and
patches for the two existing tests (both patches add further checks).
With JamVM 1.1.4 I get a number of failures. The first two I think are
due to a bug in JamVM (see my post earlier today re: Float.compare() and
Double.compare()). I haven't investigated the other failures in detail,
but they are all very similar and probably have the same underlying
cause (I may have some time next week to look at this more closely).
All checks pass using Sun's JDK 1.4:
dgilbert@linux42:~/workspace/mauve> jamvm -cp .
gnu.testlet.SimpleTestHarness -file CurrentTests.txt -debug
FAIL: gnu.testlet.java.util.Arrays.equals: Arrays.equals(double[],
double[] (number 2)
FAIL: gnu.testlet.java.util.Arrays.equals: Arrays.equals(float[],
float[] (number 2)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(byte[], int, int)
(number 1)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(byte[], int, int)
(number 2)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(byte[], int, int)
(number 3)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(byte[], int, int)
(number 8)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(char[], int, int)
(number 1)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(char[], int, int)
(number 2)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(char[], int, int)
(number 3)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(char[], int, int)
(number 8)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(double[], int, int)
(number 1)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(double[], int, int)
(number 2)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(double[], int, int)
(number 3)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(double[], int, int)
(number 8)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(float[], int, int)
(number 1)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(float[], int, int)
(number 2)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(float[], int, int)
(number 3)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(float[], int, int)
(number 8)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(int[], int, int)
(number 1)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(int[], int, int)
(number 2)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(int[], int, int)
(number 3)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(int[], int, int)
(number 8)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(long[], int, int)
(number 1)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(long[], int, int)
(number 2)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(long[], int, int)
(number 3)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(long[], int, int)
(number 8)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(Object[], int, int)
(number 8)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(short[], int, int)
(number 1)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(short[], int, int)
(number 2)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(short[], int, int)
(number 3)
FAIL: gnu.testlet.java.util.Arrays.sort: Arrays.sort(short[], int, int)
(number 8)
31 of 366 tests failed
dgilbert@linux42:~/workspace/mauve> java14 -cp .
gnu.testlet.SimpleTestHarness -file CurrentTests.txt -debug
0 of 366 tests failed
Regards,
Dave Gilbert
http://www.jfree.org
//Tags: JDK1.4
//Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
//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, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA.
package gnu.testlet.java.util.Arrays;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.RandomAccess;
/**
* Some tests for the asList() method in the {@link Arrays} class.
*/
public class asList implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
Object[] a1 = new Object[] {"1", "2", "3"};
List l1 = Arrays.asList(a1);
// check that the list is the same as the array...
harness.check(l1.size() == 3);
harness.check(l1.get(0).equals("1"));
harness.check(l1.get(1).equals("2"));
harness.check(l1.get(2).equals("3"));
harness.check(l1 instanceof RandomAccess);
harness.check(l1 instanceof Serializable);
// a change to the list updates the array...
l1.set(1, "99");
harness.check(a1[1].equals("99"));
// a change to the array updates the list...
a1[1] = "100";
harness.check(l1.get(1).equals("100"));
// check unsupported operations
boolean pass = false;
try
{
l1.add("new item");
}
catch (UnsupportedOperationException e)
{
pass = true;
}
harness.check(pass);
pass = false;
try
{
l1.clear();
}
catch (UnsupportedOperationException e)
{
pass = true;
}
harness.check(pass);
try
{
l1.remove(0);
}
catch (UnsupportedOperationException e)
{
pass = true;
}
harness.check(pass);
try
{
l1.remove("1");
}
catch (UnsupportedOperationException e)
{
pass = true;
}
harness.check(pass);
// check null argument
pass = false;
try
{
Arrays.asList(null);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
}
}//Tags: JDK1.2
//Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
//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, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA.
package gnu.testlet.java.util.Arrays;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.util.Arrays;
import java.util.Comparator;
/**
* Some tests for the binarySearch() method in the {@link Arrays} class.
*/
public class binarySearch implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness) {
testByte(harness);
testChar(harness);
testDouble(harness);
testFloat(harness);
testInt(harness);
testLong(harness);
testObject(harness);
testShort(harness);
}
private void testByte(TestHarness harness)
{
harness.checkPoint("Arrays.binarySearch(byte[], byte)");
byte[] b1 = new byte[] {1, 2, 3};
harness.check(Arrays.binarySearch(b1, (byte) 0) == -1);
harness.check(Arrays.binarySearch(b1, (byte) 1) == 0);
harness.check(Arrays.binarySearch(b1, (byte) 2) == 1);
harness.check(Arrays.binarySearch(b1, (byte) 3) == 2);
harness.check(Arrays.binarySearch(b1, (byte) 4) == -4);
boolean pass = false;
try
{
Arrays.binarySearch((byte[]) null, (byte) 0);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
}
private void testChar(TestHarness harness)
{
harness.checkPoint("Arrays.binarySearch(char[], char)");
char[] b1 = new char[] {'1', '2', '3'};
harness.check(Arrays.binarySearch(b1, '0') == -1);
harness.check(Arrays.binarySearch(b1, '1') == 0);
harness.check(Arrays.binarySearch(b1, '2') == 1);
harness.check(Arrays.binarySearch(b1, '3') == 2);
harness.check(Arrays.binarySearch(b1, '4') == -4);
boolean pass = false;
try
{
Arrays.binarySearch((char[]) null, '0');
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
}
private void testDouble(TestHarness harness)
{
harness.checkPoint("Arrays.binarySearch(double[], double)");
double[] b1 = new double[] {1.0, 2.0, 3.0};
harness.check(Arrays.binarySearch(b1, 0.0) == -1);
harness.check(Arrays.binarySearch(b1, 1.0) == 0);
harness.check(Arrays.binarySearch(b1, 2.0) == 1);
harness.check(Arrays.binarySearch(b1, 3.0) == 2);
harness.check(Arrays.binarySearch(b1, 4.0) == -4);
boolean pass = false;
try
{
Arrays.binarySearch((double[]) null, 0.0);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
}
private void testFloat(TestHarness harness)
{
harness.checkPoint("Arrays.binarySearch(float[], float)");
float[] b1 = new float[] {1.0f, 2.0f, 3.0f};
harness.check(Arrays.binarySearch(b1, 0.0f) == -1);
harness.check(Arrays.binarySearch(b1, 1.0f) == 0);
harness.check(Arrays.binarySearch(b1, 2.0f) == 1);
harness.check(Arrays.binarySearch(b1, 3.0f) == 2);
harness.check(Arrays.binarySearch(b1, 4.0f) == -4);
boolean pass = false;
try
{
Arrays.binarySearch((float[]) null, 0.0f);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
}
private void testInt(TestHarness harness)
{
harness.checkPoint("Arrays.binarySearch(int[], int)");
int[] b1 = new int[] {1, 2, 3};
harness.check(Arrays.binarySearch(b1, 0) == -1);
harness.check(Arrays.binarySearch(b1, 1) == 0);
harness.check(Arrays.binarySearch(b1, 2) == 1);
harness.check(Arrays.binarySearch(b1, 3) == 2);
harness.check(Arrays.binarySearch(b1, 4) == -4);
boolean pass = false;
try
{
Arrays.binarySearch((int[]) null, 0);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
}
private void testLong(TestHarness harness)
{
harness.checkPoint("Arrays.binarySearch(long[], long)");
long[] b1 = new long[] {1, 2, 3};
harness.check(Arrays.binarySearch(b1, 0) == -1);
harness.check(Arrays.binarySearch(b1, 1) == 0);
harness.check(Arrays.binarySearch(b1, 2) == 1);
harness.check(Arrays.binarySearch(b1, 3) == 2);
harness.check(Arrays.binarySearch(b1, 4) == -4);
boolean pass = false;
try
{
Arrays.binarySearch((long[]) null, 0);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
}
private void testObject(TestHarness harness)
{
harness.checkPoint("Arrays.binarySearch(Object[], Object)");
Object[] b1 = new Object[] {"1", "2", "3"};
harness.check(Arrays.binarySearch(b1, "0") == -1);
harness.check(Arrays.binarySearch(b1, "1") == 0);
harness.check(Arrays.binarySearch(b1, "2") == 1);
harness.check(Arrays.binarySearch(b1, "3") == 2);
harness.check(Arrays.binarySearch(b1, "4") == -4);
// searching for null throws NullPointerException
boolean pass = false;
try
{
Arrays.binarySearch(b1, null);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
pass = false;
try
{
Arrays.binarySearch((Object[]) null, "0");
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
harness.checkPoint("Arrays.binarySearch(Object[], Object, Comparator)");
harness.check(Arrays.binarySearch(b1, "0", (Comparator) null) == -1);
harness.check(Arrays.binarySearch(b1, "1", (Comparator) null) == 0);
harness.check(Arrays.binarySearch(b1, "2", (Comparator) null) == 1);
harness.check(Arrays.binarySearch(b1, "3", (Comparator) null) == 2);
harness.check(Arrays.binarySearch(b1, "4", (Comparator) null) == -4);
Arrays.sort(b1, new ReverseComparator());
harness.check(Arrays.binarySearch(b1, "0", new ReverseComparator()) == -4);
harness.check(Arrays.binarySearch(b1, "1", new ReverseComparator()) == 2);
harness.check(Arrays.binarySearch(b1, "2", new ReverseComparator()) == 1);
harness.check(Arrays.binarySearch(b1, "3", new ReverseComparator()) == 0);
harness.check(Arrays.binarySearch(b1, "4", new ReverseComparator()) == -1);
}
private void testShort(TestHarness harness)
{
harness.checkPoint("Arrays.binarySearch(short[], short)");
short[] b1 = new short[] {1, 2, 3};
harness.check(Arrays.binarySearch(b1, (short) 0) == -1);
harness.check(Arrays.binarySearch(b1, (short) 1) == 0);
harness.check(Arrays.binarySearch(b1, (short) 2) == 1);
harness.check(Arrays.binarySearch(b1, (short) 3) == 2);
harness.check(Arrays.binarySearch(b1, (short) 4) == -4);
boolean pass = false;
try
{
Arrays.binarySearch((short[]) null, (short) 0);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
}
static class ReverseComparator implements Comparator {
public int compare(Object o1, Object o2) {
int i1 = Integer.valueOf(o1.toString()).intValue();
int i2 = Integer.valueOf(o2.toString()).intValue();
return (i2 - i1);
}
}
}
//Tags: JDK1.2
//Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
//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, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA. */
package gnu.testlet.java.util.Arrays;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.util.Arrays;
public class fill implements Testlet
{
public void test (TestHarness harness)
{
testBoolean(harness);
testByte(harness);
testChar(harness);
testDouble(harness);
testFloat(harness);
testInt(harness);
testLong(harness);
testObject(harness);
testShort(harness);
}
private void testBoolean(TestHarness harness)
{
harness.checkPoint("Arrays.fill(boolean[], boolean");
boolean[] b1 = new boolean[0];
boolean[] b2 = new boolean[1];
boolean[] b3 = new boolean[2];
Arrays.fill(b1, true);
harness.check(b1.length == 0);
Arrays.fill(b2, true);
harness.check(b2[0] == true);
Arrays.fill(b3, true);
harness.check(b3[0] == true);
harness.check(b3[1] == true);
boolean pass = false;
try
{
Arrays.fill((boolean[]) null, true);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
harness.checkPoint("Arrays.fill(boolean[], int, int, boolean");
Arrays.fill(b1, 0, 0, false);
Arrays.fill(b2, 0, 1, false);
harness.check(b2[0] == false);
Arrays.fill(b3, 1, 2, false);
harness.check(b3[0] == true);
harness.check(b3[1] == false);
// from index should be <= toIndex
pass = false;
try
{
Arrays.fill(b3, 2, 1, false);
}
catch (IllegalArgumentException e)
{
pass = true;
}
harness.check(pass);
// from index should be >= 0
pass = false;
try
{
Arrays.fill(b3, -1, 1, false);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
// to index should be < array.length
pass = false;
try
{
Arrays.fill(b3, 0, 4, false);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
}
private void testByte(TestHarness harness)
{
harness.checkPoint("Arrays.fill(byte[], byte");
byte[] b1 = new byte[0];
byte[] b2 = new byte[1];
byte[] b3 = new byte[2];
Arrays.fill(b1, (byte) 1);
harness.check(b1.length == 0);
Arrays.fill(b2, (byte) 1);
harness.check(b2[0] == (byte) 1);
Arrays.fill(b3, (byte) 1);
harness.check(b3[0] == (byte) 1);
harness.check(b3[1] == (byte) 1);
boolean pass = false;
try
{
Arrays.fill((byte[]) null, (byte) 1);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
harness.checkPoint("Arrays.fill(byte[], int, int, byte");
Arrays.fill(b1, 0, 0, (byte) 2);
Arrays.fill(b2, 0, 1, (byte) 2);
harness.check(b2[0] == (byte) 2);
Arrays.fill(b3, 1, 2, (byte) 2);
harness.check(b3[0] == (byte) 1);
harness.check(b3[1] == (byte) 2);
// from index should be <= toIndex
pass = false;
try
{
Arrays.fill(b3, 2, 1, (byte) 0);
}
catch (IllegalArgumentException e)
{
pass = true;
}
harness.check(pass);
// from index should be >= 0
pass = false;
try
{
Arrays.fill(b3, -1, 1, (byte) 0);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
// to index should be < array.length
pass = false;
try
{
Arrays.fill(b3, 0, 4, (byte) 0);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
}
private void testChar(TestHarness harness)
{
harness.checkPoint("Arrays.fill(char[], char");
char[] b1 = new char[0];
char[] b2 = new char[1];
char[] b3 = new char[2];
Arrays.fill(b1, 'A');
harness.check(b1.length == 0);
Arrays.fill(b2, 'A');
harness.check(b2[0] == 'A');
Arrays.fill(b3, 'A');
harness.check(b3[0] == 'A');
harness.check(b3[1] == 'A');
boolean pass = false;
try
{
Arrays.fill((char[]) null, 'A');
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
harness.checkPoint("Arrays.fill(char[], int, int, char");
Arrays.fill(b1, 0, 0, 'B');
Arrays.fill(b2, 0, 1, 'B');
harness.check(b2[0] == 'B');
Arrays.fill(b3, 1, 2, 'B');
harness.check(b3[0] == 'A');
harness.check(b3[1] == 'B');
// from index should be <= toIndex
pass = false;
try
{
Arrays.fill(b3, 2, 1, 'B');
}
catch (IllegalArgumentException e)
{
pass = true;
}
harness.check(pass);
// from index should be >= 0
pass = false;
try
{
Arrays.fill(b3, -1, 1, 'B');
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
// to index should be < array.length
pass = false;
try
{
Arrays.fill(b3, 0, 4, 'B');
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
}
private void testDouble(TestHarness harness)
{
harness.checkPoint("Arrays.fill(double[], double");
double[] b1 = new double[0];
double[] b2 = new double[1];
double[] b3 = new double[2];
Arrays.fill(b1, 1.0);
harness.check(b1.length == 0);
Arrays.fill(b2, 1.0);
harness.check(b2[0] == 1.0);
Arrays.fill(b3, 1.0);
harness.check(b3[0] == 1.0);
harness.check(b3[1] == 1.0);
boolean pass = false;
try
{
Arrays.fill((double[]) null, 1.0);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
harness.checkPoint("Arrays.fill(double[], int, int, double");
Arrays.fill(b1, 0, 0, 2.0);
Arrays.fill(b2, 0, 1, 2.0);
harness.check(b2[0] == 2.0);
Arrays.fill(b3, 1, 2, 2.0);
harness.check(b3[0] == 1.0);
harness.check(b3[1] == 2.0);
// from index should be <= toIndex
pass = false;
try
{
Arrays.fill(b3, 2, 1, 2.0);
}
catch (IllegalArgumentException e)
{
pass = true;
}
harness.check(pass);
// from index should be >= 0
pass = false;
try
{
Arrays.fill(b3, -1, 1, 2.0);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
// to index should be < array.length
pass = false;
try
{
Arrays.fill(b3, 0, 4, 2.0);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
}
private void testFloat(TestHarness harness)
{
harness.checkPoint("Arrays.fill(float[], float");
float[] b1 = new float[0];
float[] b2 = new float[1];
float[] b3 = new float[2];
Arrays.fill(b1, 1.0f);
harness.check(b1.length == 0);
Arrays.fill(b2, 1.0f);
harness.check(b2[0] == 1.0f);
Arrays.fill(b3, 1.0f);
harness.check(b3[0] == 1.0f);
harness.check(b3[1] == 1.0f);
boolean pass = false;
try
{
Arrays.fill((float[]) null, 1.0f);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
harness.checkPoint("Arrays.fill(float[], int, int, float");
Arrays.fill(b1, 0, 0, 2.0f);
Arrays.fill(b2, 0, 1, 2.0f);
harness.check(b2[0] == 2.0f);
Arrays.fill(b3, 1, 2, 2.0f);
harness.check(b3[0] == 1.0);
harness.check(b3[1] == 2.0);
// from index should be <= toIndex
pass = false;
try
{
Arrays.fill(b3, 2, 1, 2.0f);
}
catch (IllegalArgumentException e)
{
pass = true;
}
harness.check(pass);
// from index should be >= 0
pass = false;
try
{
Arrays.fill(b3, -1, 1, 2.0f);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
// to index should be < array.length
pass = false;
try
{
Arrays.fill(b3, 0, 4, 2.0f);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
}
private void testInt(TestHarness harness)
{
harness.checkPoint("Arrays.fill(int[], int");
int[] b1 = new int[0];
int[] b2 = new int[1];
int[] b3 = new int[2];
Arrays.fill(b1, 1);
harness.check(b1.length == 0);
Arrays.fill(b2, 1);
harness.check(b2[0] == 1);
Arrays.fill(b3, 1);
harness.check(b3[0] == 1);
harness.check(b3[1] == 1);
boolean pass = false;
try
{
Arrays.fill((int[]) null, 1);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
harness.checkPoint("Arrays.fill(int[], int, int, int");
Arrays.fill(b1, 0, 0, 2);
Arrays.fill(b2, 0, 1, 2);
harness.check(b2[0] == 2);
Arrays.fill(b3, 1, 2, 2);
harness.check(b3[0] == 1);
harness.check(b3[1] == 2);
// from index should be <= toIndex
pass = false;
try
{
Arrays.fill(b3, 2, 1, 2);
}
catch (IllegalArgumentException e)
{
pass = true;
}
harness.check(pass);
// from index should be >= 0
pass = false;
try
{
Arrays.fill(b3, -1, 1, 2);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
// to index should be < array.length
pass = false;
try
{
Arrays.fill(b3, 0, 4, 2);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
}
private void testLong(TestHarness harness)
{
harness.checkPoint("Arrays.fill(long[], long");
long[] b1 = new long[0];
long[] b2 = new long[1];
long[] b3 = new long[2];
Arrays.fill(b1, 1);
harness.check(b1.length == 0);
Arrays.fill(b2, 1);
harness.check(b2[0] == 1);
Arrays.fill(b3, 1);
harness.check(b3[0] == 1);
harness.check(b3[1] == 1);
boolean pass = false;
try
{
Arrays.fill((long[]) null, 1);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
harness.checkPoint("Arrays.fill(long[], int, int, long");
Arrays.fill(b1, 0, 0, 2);
Arrays.fill(b2, 0, 1, 2);
harness.check(b2[0] == 2);
Arrays.fill(b3, 1, 2, 2);
harness.check(b3[0] == 1);
harness.check(b3[1] == 2);
// from index should be <= toIndex
pass = false;
try
{
Arrays.fill(b3, 2, 1, 2);
}
catch (IllegalArgumentException e)
{
pass = true;
}
harness.check(pass);
// from index should be >= 0
pass = false;
try
{
Arrays.fill(b3, -1, 1, 2);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
// to index should be < array.length
pass = false;
try
{
Arrays.fill(b3, 0, 4, 2);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
}
private void testObject(TestHarness harness)
{
harness.checkPoint("Arrays.fill(Object[], Object");
Object[] b1 = new Object[0];
Object[] b2 = new Object[1];
Object[] b3 = new Object[2];
Arrays.fill(b1, "1");
harness.check(b1.length == 0);
Arrays.fill(b2, "1");
harness.check(b2[0] == "1");
Arrays.fill(b3, "1");
harness.check(b3[0] == "1");
harness.check(b3[1] == "1");
boolean pass = false;
try
{
Arrays.fill((Object[]) null, "1");
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
harness.checkPoint("Arrays.fill(Object[], int, int, long");
Arrays.fill(b1, 0, 0, "2");
Arrays.fill(b2, 0, 1, "2");
harness.check(b2[0] == "2");
Arrays.fill(b3, 1, 2, "2");
harness.check(b3[0] == "1");
harness.check(b3[1] == "2");
// from index should be <= toIndex
pass = false;
try
{
Arrays.fill(b3, 2, 1, "2");
}
catch (IllegalArgumentException e)
{
pass = true;
}
harness.check(pass);
// from index should be >= 0
pass = false;
try
{
Arrays.fill(b3, -1, 1, "2");
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
// to index should be < array.length
pass = false;
try
{
Arrays.fill(b3, 0, 4, "2");
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
}
private void testShort(TestHarness harness)
{
harness.checkPoint("Arrays.fill(short[], short");
short[] b1 = new short[0];
short[] b2 = new short[1];
short[] b3 = new short[2];
Arrays.fill(b1, (short) 1);
harness.check(b1.length == 0);
Arrays.fill(b2, (short) 1);
harness.check(b2[0] == 1);
Arrays.fill(b3, (short) 1);
harness.check(b3[0] == 1);
harness.check(b3[1] == 1);
boolean pass = false;
try
{
Arrays.fill((int[]) null, 1);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
harness.checkPoint("Arrays.fill(short)[], int, int, short");
Arrays.fill(b1, 0, 0, (short) 2);
Arrays.fill(b2, 0, 1, (short) 2);
harness.check(b2[0] == 2);
Arrays.fill(b3, 1, 2, (short) 2);
harness.check(b3[0] == 1);
harness.check(b3[1] == 2);
// from index should be <= toIndex
pass = false;
try
{
Arrays.fill(b3, 2, 1, (short) 2);
}
catch (IllegalArgumentException e)
{
pass = true;
}
harness.check(pass);
// from index should be >= 0
pass = false;
try
{
Arrays.fill(b3, -1, 1, (short) 2);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
// to index should be < array.length
pass = false;
try
{
Arrays.fill(b3, 0, 4, (short) 2);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
}
}
Index: equals.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/util/Arrays/equals.java,v
retrieving revision 1.1
diff -u -r1.1 equals.java
--- equals.java 24 May 2003 23:18:38 -0000 1.1
+++ equals.java 27 Aug 2004 16:14:54 -0000
@@ -1,6 +1,7 @@
// Tags: JDK1.2
// Copyright (C) 2003 Daniel Bonniot <bonniot@users.sf.net>
+// 2004 David Gilbert <david.gilbert@object-refinery.com>
// This file is part of Mauve.
@@ -21,10 +22,10 @@
package gnu.testlet.java.util.Arrays;
-import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
-import java.util.*;
+import java.util.Arrays;
public class equals implements Testlet
{
@@ -34,5 +35,172 @@
final String[] a2 = { "", null };
harness.check(Arrays.equals(a1, a2));
+
+ // added by David Gilbert
+ testBoolean(harness);
+ testByte(harness);
+ testChar(harness);
+ testDouble(harness);
+ testFloat(harness);
+ testInt(harness);
+ testLong(harness);
+ testObject(harness);
+ testShort(harness);
+ }
+
+ private void testBoolean(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.equals(boolean[], boolean[]");
+ harness.check(Arrays.equals((boolean[]) null, (boolean[]) null));
+ boolean[] b1 = new boolean[] {true, false};
+ boolean[] b2 = new boolean[] {true, false};
+ boolean[] b3 = new boolean[] {false, true};
+ boolean[] b4 = new boolean[] {true};
+ boolean[] b5 = new boolean[] {true, false, false};
+ boolean[] b6 = null;
+ harness.check(Arrays.equals(b1, b2));
+ harness.check(!Arrays.equals(b1, b3));
+ harness.check(!Arrays.equals(b1, b4));
+ harness.check(!Arrays.equals(b1, b5));
+ harness.check(!Arrays.equals(b1, b6));
+ }
+
+ private void testByte(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.equals(byte[], byte[]");
+ harness.check(Arrays.equals((byte[]) null, (byte[]) null));
+ byte[] b1 = new byte[] {1, 0};
+ byte[] b2 = new byte[] {1, 0};
+ byte[] b3 = new byte[] {0, 1};
+ byte[] b4 = new byte[] {1};
+ byte[] b5 = new byte[] {1, 0, 0};
+ byte[] b6 = null;
+ harness.check(Arrays.equals(b1, b2));
+ harness.check(!Arrays.equals(b1, b3));
+ harness.check(!Arrays.equals(b1, b4));
+ harness.check(!Arrays.equals(b1, b5));
+ harness.check(!Arrays.equals(b1, b6));
+ }
+
+ private void testChar(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.equals(char[], char[]");
+ harness.check(Arrays.equals((char[]) null, (char[]) null));
+ char[] b1 = new char[] {'1', '0'};
+ char[] b2 = new char[] {'1', '0'};
+ char[] b3 = new char[] {'0', '1'};
+ char[] b4 = new char[] {'1'};
+ char[] b5 = new char[] {'1', '0', '0'};
+ char[] b6 = null;
+ harness.check(Arrays.equals(b1, b2));
+ harness.check(!Arrays.equals(b1, b3));
+ harness.check(!Arrays.equals(b1, b4));
+ harness.check(!Arrays.equals(b1, b5));
+ harness.check(!Arrays.equals(b1, b6));
+ }
+
+ private void testDouble(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.equals(double[], double[]");
+ harness.check(Arrays.equals((double[]) null, (double[]) null));
+ double[] b1 = new double[] {1, 0};
+ double[] b2 = new double[] {1, 0};
+ double[] b3 = new double[] {0, 1};
+ double[] b4 = new double[] {1};
+ double[] b5 = new double[] {1, 0, 0};
+ double[] b6 = null;
+ harness.check(Arrays.equals(b1, b2));
+ harness.check(!Arrays.equals(b1, b3));
+ harness.check(!Arrays.equals(b1, b4));
+ harness.check(!Arrays.equals(b1, b5));
+ harness.check(!Arrays.equals(b1, b6));
+ }
+
+ private void testFloat(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.equals(float[], float[]");
+ harness.check(Arrays.equals((float[]) null, (float[]) null));
+ float[] b1 = new float[] {1, 0};
+ float[] b2 = new float[] {1, 0};
+ float[] b3 = new float[] {0, 1};
+ float[] b4 = new float[] {1};
+ float[] b5 = new float[] {1, 0, 0};
+ float[] b6 = null;
+ harness.check(Arrays.equals(b1, b2));
+ harness.check(!Arrays.equals(b1, b3));
+ harness.check(!Arrays.equals(b1, b4));
+ harness.check(!Arrays.equals(b1, b5));
+ harness.check(!Arrays.equals(b1, b6));
+ }
+
+ private void testInt(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.equals(int[], int[]");
+ harness.check(Arrays.equals((int[]) null, (int[]) null));
+ int[] b1 = new int[] {1, 0};
+ int[] b2 = new int[] {1, 0};
+ int[] b3 = new int[] {0, 1};
+ int[] b4 = new int[] {1};
+ int[] b5 = new int[] {1, 0, 0};
+ int[] b6 = null;
+ harness.check(Arrays.equals(b1, b2));
+ harness.check(!Arrays.equals(b1, b3));
+ harness.check(!Arrays.equals(b1, b4));
+ harness.check(!Arrays.equals(b1, b5));
+ harness.check(!Arrays.equals(b1, b6));
+ }
+
+ private void testLong(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.equals(long[], long[]");
+ harness.check(Arrays.equals((long[]) null, (long[]) null));
+ long[] b1 = new long[] {1, 0};
+ long[] b2 = new long[] {1, 0};
+ long[] b3 = new long[] {0, 1};
+ long[] b4 = new long[] {1};
+ long[] b5 = new long[] {1, 0, 0};
+ long[] b6 = null;
+ harness.check(Arrays.equals(b1, b2));
+ harness.check(!Arrays.equals(b1, b3));
+ harness.check(!Arrays.equals(b1, b4));
+ harness.check(!Arrays.equals(b1, b5));
+ harness.check(!Arrays.equals(b1, b6));
+ }
+
+ private void testObject(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.equals(Object[], Object[]");
+ harness.check(Arrays.equals((Object[]) null, (Object[]) null));
+ Object[] b1 = new Object[] {"1", "0", null};
+ Object[] b2 = new Object[] {"1", "0", null};
+ Object[] b3 = new Object[] {"0", "1"};
+ Object[] b4 = new Object[] {"1"};
+ Object[] b5 = new Object[] {"1", "0", "0"};
+ Object[] b6 = new Object[] {"1", "0", null, "0"};
+ Object[] b7 = null;
+ harness.check(Arrays.equals(b1, b2));
+ harness.check(!Arrays.equals(b1, b3));
+ harness.check(!Arrays.equals(b1, b4));
+ harness.check(!Arrays.equals(b1, b5));
+ harness.check(!Arrays.equals(b1, b6));
+ harness.check(!Arrays.equals(b1, b7));
+ }
+
+ private void testShort(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.equals(short[], short[]");
+ harness.check(Arrays.equals((short[]) null, (short[]) null));
+ short[] b1 = new short[] {1, 0};
+ short[] b2 = new short[] {1, 0};
+ short[] b3 = new short[] {0, 1};
+ short[] b4 = new short[] {1};
+ short[] b5 = new short[] {1, 0, 0};
+ short[] b6 = null;
+ harness.check(Arrays.equals(b1, b2));
+ harness.check(!Arrays.equals(b1, b3));
+ harness.check(!Arrays.equals(b1, b4));
+ harness.check(!Arrays.equals(b1, b5));
+ harness.check(!Arrays.equals(b1, b6));
}
+
}
Index: asList.java
===================================================================
RCS file: asList.java
diff -N asList.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ asList.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,120 @@
+//Tags: JDK1.4
+
+//Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
+
+//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, 59 Temple Place - Suite 330,
+//Boston, MA 02111-1307, USA.
+
+package gnu.testlet.java.util.Arrays;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.List;
+import java.util.RandomAccess;
+
+/**
+ * Some tests for the asList() method in the {@link Arrays} class.
+ */
+public class asList implements Testlet
+{
+
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ Object[] a1 = new Object[] {"1", "2", "3"};
+ List l1 = Arrays.asList(a1);
+
+ // check that the list is the same as the array...
+ harness.check(l1.size() == 3);
+ harness.check(l1.get(0).equals("1"));
+ harness.check(l1.get(1).equals("2"));
+ harness.check(l1.get(2).equals("3"));
+ harness.check(l1 instanceof RandomAccess);
+ harness.check(l1 instanceof Serializable);
+
+ // a change to the list updates the array...
+ l1.set(1, "99");
+ harness.check(a1[1].equals("99"));
+
+ // a change to the array updates the list...
+ a1[1] = "100";
+ harness.check(l1.get(1).equals("100"));
+
+ // check unsupported operations
+ boolean pass = false;
+ try
+ {
+ l1.add("new item");
+ }
+ catch (UnsupportedOperationException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ l1.clear();
+ }
+ catch (UnsupportedOperationException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ try
+ {
+ l1.remove(0);
+ }
+ catch (UnsupportedOperationException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ try
+ {
+ l1.remove("1");
+ }
+ catch (UnsupportedOperationException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // check null argument
+ pass = false;
+ try
+ {
+ Arrays.asList(null);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+}
Index: binarySearch.java
===================================================================
RCS file: binarySearch.java
diff -N binarySearch.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ binarySearch.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,262 @@
+//Tags: JDK1.2
+
+//Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
+
+//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, 59 Temple Place - Suite 330,
+//Boston, MA 02111-1307, USA.
+
+package gnu.testlet.java.util.Arrays;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+/**
+* Some tests for the binarySearch() method in the {@link Arrays} class.
+*/
+public class binarySearch implements Testlet
+{
+
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness) {
+ testByte(harness);
+ testChar(harness);
+ testDouble(harness);
+ testFloat(harness);
+ testInt(harness);
+ testLong(harness);
+ testObject(harness);
+ testShort(harness);
+ }
+
+ private void testByte(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(byte[], byte)");
+ byte[] b1 = new byte[] {1, 2, 3};
+ harness.check(Arrays.binarySearch(b1, (byte) 0) == -1);
+ harness.check(Arrays.binarySearch(b1, (byte) 1) == 0);
+ harness.check(Arrays.binarySearch(b1, (byte) 2) == 1);
+ harness.check(Arrays.binarySearch(b1, (byte) 3) == 2);
+ harness.check(Arrays.binarySearch(b1, (byte) 4) == -4);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch((byte[]) null, (byte) 0);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testChar(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(char[], char)");
+ char[] b1 = new char[] {'1', '2', '3'};
+ harness.check(Arrays.binarySearch(b1, '0') == -1);
+ harness.check(Arrays.binarySearch(b1, '1') == 0);
+ harness.check(Arrays.binarySearch(b1, '2') == 1);
+ harness.check(Arrays.binarySearch(b1, '3') == 2);
+ harness.check(Arrays.binarySearch(b1, '4') == -4);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch((char[]) null, '0');
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testDouble(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(double[], double)");
+ double[] b1 = new double[] {1.0, 2.0, 3.0};
+ harness.check(Arrays.binarySearch(b1, 0.0) == -1);
+ harness.check(Arrays.binarySearch(b1, 1.0) == 0);
+ harness.check(Arrays.binarySearch(b1, 2.0) == 1);
+ harness.check(Arrays.binarySearch(b1, 3.0) == 2);
+ harness.check(Arrays.binarySearch(b1, 4.0) == -4);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch((double[]) null, 0.0);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testFloat(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(float[], float)");
+ float[] b1 = new float[] {1.0f, 2.0f, 3.0f};
+ harness.check(Arrays.binarySearch(b1, 0.0f) == -1);
+ harness.check(Arrays.binarySearch(b1, 1.0f) == 0);
+ harness.check(Arrays.binarySearch(b1, 2.0f) == 1);
+ harness.check(Arrays.binarySearch(b1, 3.0f) == 2);
+ harness.check(Arrays.binarySearch(b1, 4.0f) == -4);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch((float[]) null, 0.0f);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testInt(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(int[], int)");
+ int[] b1 = new int[] {1, 2, 3};
+ harness.check(Arrays.binarySearch(b1, 0) == -1);
+ harness.check(Arrays.binarySearch(b1, 1) == 0);
+ harness.check(Arrays.binarySearch(b1, 2) == 1);
+ harness.check(Arrays.binarySearch(b1, 3) == 2);
+ harness.check(Arrays.binarySearch(b1, 4) == -4);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch((int[]) null, 0);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testLong(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(long[], long)");
+ long[] b1 = new long[] {1, 2, 3};
+ harness.check(Arrays.binarySearch(b1, 0) == -1);
+ harness.check(Arrays.binarySearch(b1, 1) == 0);
+ harness.check(Arrays.binarySearch(b1, 2) == 1);
+ harness.check(Arrays.binarySearch(b1, 3) == 2);
+ harness.check(Arrays.binarySearch(b1, 4) == -4);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch((long[]) null, 0);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testObject(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(Object[], Object)");
+ Object[] b1 = new Object[] {"1", "2", "3"};
+ harness.check(Arrays.binarySearch(b1, "0") == -1);
+ harness.check(Arrays.binarySearch(b1, "1") == 0);
+ harness.check(Arrays.binarySearch(b1, "2") == 1);
+ harness.check(Arrays.binarySearch(b1, "3") == 2);
+ harness.check(Arrays.binarySearch(b1, "4") == -4);
+
+ // searching for null throws NullPointerException
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch(b1, null);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.binarySearch((Object[]) null, "0");
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.binarySearch(Object[], Object, Comparator)");
+ harness.check(Arrays.binarySearch(b1, "0", (Comparator) null) == -1);
+ harness.check(Arrays.binarySearch(b1, "1", (Comparator) null) == 0);
+ harness.check(Arrays.binarySearch(b1, "2", (Comparator) null) == 1);
+ harness.check(Arrays.binarySearch(b1, "3", (Comparator) null) == 2);
+ harness.check(Arrays.binarySearch(b1, "4", (Comparator) null) == -4);
+
+ Arrays.sort(b1, new ReverseComparator());
+ harness.check(Arrays.binarySearch(b1, "0", new ReverseComparator()) == -4);
+ harness.check(Arrays.binarySearch(b1, "1", new ReverseComparator()) == 2);
+ harness.check(Arrays.binarySearch(b1, "2", new ReverseComparator()) == 1);
+ harness.check(Arrays.binarySearch(b1, "3", new ReverseComparator()) == 0);
+ harness.check(Arrays.binarySearch(b1, "4", new ReverseComparator()) == -1);
+ }
+
+ private void testShort(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(short[], short)");
+ short[] b1 = new short[] {1, 2, 3};
+ harness.check(Arrays.binarySearch(b1, (short) 0) == -1);
+ harness.check(Arrays.binarySearch(b1, (short) 1) == 0);
+ harness.check(Arrays.binarySearch(b1, (short) 2) == 1);
+ harness.check(Arrays.binarySearch(b1, (short) 3) == 2);
+ harness.check(Arrays.binarySearch(b1, (short) 4) == -4);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch((short[]) null, (short) 0);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ static class ReverseComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ int i1 = Integer.valueOf(o1.toString()).intValue();
+ int i2 = Integer.valueOf(o2.toString()).intValue();
+ return (i2 - i1);
+ }
+ }
+
+}
Index: fill.java
===================================================================
RCS file: fill.java
diff -N fill.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ fill.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,728 @@
+//Tags: JDK1.2
+
+//Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
+
+//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, 59 Temple Place - Suite 330,
+//Boston, MA 02111-1307, USA. */
+
+package gnu.testlet.java.util.Arrays;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.util.Arrays;
+
+public class fill implements Testlet
+{
+ public void test (TestHarness harness)
+ {
+ testBoolean(harness);
+ testByte(harness);
+ testChar(harness);
+ testDouble(harness);
+ testFloat(harness);
+ testInt(harness);
+ testLong(harness);
+ testObject(harness);
+ testShort(harness);
+ }
+
+ private void testBoolean(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(boolean[], boolean");
+ boolean[] b1 = new boolean[0];
+ boolean[] b2 = new boolean[1];
+ boolean[] b3 = new boolean[2];
+
+ Arrays.fill(b1, true);
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, true);
+ harness.check(b2[0] == true);
+
+ Arrays.fill(b3, true);
+ harness.check(b3[0] == true);
+ harness.check(b3[1] == true);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((boolean[]) null, true);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(boolean[], int, int, boolean");
+
+ Arrays.fill(b1, 0, 0, false);
+
+ Arrays.fill(b2, 0, 1, false);
+ harness.check(b2[0] == false);
+
+ Arrays.fill(b3, 1, 2, false);
+ harness.check(b3[0] == true);
+ harness.check(b3[1] == false);
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, false);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, false);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testByte(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(byte[], byte");
+ byte[] b1 = new byte[0];
+ byte[] b2 = new byte[1];
+ byte[] b3 = new byte[2];
+
+ Arrays.fill(b1, (byte) 1);
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, (byte) 1);
+ harness.check(b2[0] == (byte) 1);
+
+ Arrays.fill(b3, (byte) 1);
+ harness.check(b3[0] == (byte) 1);
+ harness.check(b3[1] == (byte) 1);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((byte[]) null, (byte) 1);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(byte[], int, int, byte");
+
+ Arrays.fill(b1, 0, 0, (byte) 2);
+
+ Arrays.fill(b2, 0, 1, (byte) 2);
+ harness.check(b2[0] == (byte) 2);
+
+ Arrays.fill(b3, 1, 2, (byte) 2);
+ harness.check(b3[0] == (byte) 1);
+ harness.check(b3[1] == (byte) 2);
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, (byte) 0);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, (byte) 0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, (byte) 0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testChar(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(char[], char");
+ char[] b1 = new char[0];
+ char[] b2 = new char[1];
+ char[] b3 = new char[2];
+
+ Arrays.fill(b1, 'A');
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, 'A');
+ harness.check(b2[0] == 'A');
+
+ Arrays.fill(b3, 'A');
+ harness.check(b3[0] == 'A');
+ harness.check(b3[1] == 'A');
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((char[]) null, 'A');
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(char[], int, int, char");
+
+ Arrays.fill(b1, 0, 0, 'B');
+
+ Arrays.fill(b2, 0, 1, 'B');
+ harness.check(b2[0] == 'B');
+
+ Arrays.fill(b3, 1, 2, 'B');
+ harness.check(b3[0] == 'A');
+ harness.check(b3[1] == 'B');
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, 'B');
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, 'B');
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, 'B');
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testDouble(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(double[], double");
+ double[] b1 = new double[0];
+ double[] b2 = new double[1];
+ double[] b3 = new double[2];
+
+ Arrays.fill(b1, 1.0);
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, 1.0);
+ harness.check(b2[0] == 1.0);
+
+ Arrays.fill(b3, 1.0);
+ harness.check(b3[0] == 1.0);
+ harness.check(b3[1] == 1.0);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((double[]) null, 1.0);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(double[], int, int, double");
+
+ Arrays.fill(b1, 0, 0, 2.0);
+
+ Arrays.fill(b2, 0, 1, 2.0);
+ harness.check(b2[0] == 2.0);
+
+ Arrays.fill(b3, 1, 2, 2.0);
+ harness.check(b3[0] == 1.0);
+ harness.check(b3[1] == 2.0);
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, 2.0);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, 2.0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, 2.0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testFloat(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(float[], float");
+ float[] b1 = new float[0];
+ float[] b2 = new float[1];
+ float[] b3 = new float[2];
+
+ Arrays.fill(b1, 1.0f);
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, 1.0f);
+ harness.check(b2[0] == 1.0f);
+
+ Arrays.fill(b3, 1.0f);
+ harness.check(b3[0] == 1.0f);
+ harness.check(b3[1] == 1.0f);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((float[]) null, 1.0f);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(float[], int, int, float");
+
+ Arrays.fill(b1, 0, 0, 2.0f);
+
+ Arrays.fill(b2, 0, 1, 2.0f);
+ harness.check(b2[0] == 2.0f);
+
+ Arrays.fill(b3, 1, 2, 2.0f);
+ harness.check(b3[0] == 1.0);
+ harness.check(b3[1] == 2.0);
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, 2.0f);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, 2.0f);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, 2.0f);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testInt(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(int[], int");
+ int[] b1 = new int[0];
+ int[] b2 = new int[1];
+ int[] b3 = new int[2];
+
+ Arrays.fill(b1, 1);
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, 1);
+ harness.check(b2[0] == 1);
+
+ Arrays.fill(b3, 1);
+ harness.check(b3[0] == 1);
+ harness.check(b3[1] == 1);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((int[]) null, 1);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(int[], int, int, int");
+
+ Arrays.fill(b1, 0, 0, 2);
+
+ Arrays.fill(b2, 0, 1, 2);
+ harness.check(b2[0] == 2);
+
+ Arrays.fill(b3, 1, 2, 2);
+ harness.check(b3[0] == 1);
+ harness.check(b3[1] == 2);
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, 2);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, 2);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, 2);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testLong(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(long[], long");
+ long[] b1 = new long[0];
+ long[] b2 = new long[1];
+ long[] b3 = new long[2];
+
+ Arrays.fill(b1, 1);
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, 1);
+ harness.check(b2[0] == 1);
+
+ Arrays.fill(b3, 1);
+ harness.check(b3[0] == 1);
+ harness.check(b3[1] == 1);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((long[]) null, 1);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(long[], int, int, long");
+
+ Arrays.fill(b1, 0, 0, 2);
+
+ Arrays.fill(b2, 0, 1, 2);
+ harness.check(b2[0] == 2);
+
+ Arrays.fill(b3, 1, 2, 2);
+ harness.check(b3[0] == 1);
+ harness.check(b3[1] == 2);
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, 2);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, 2);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, 2);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testObject(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(Object[], Object");
+ Object[] b1 = new Object[0];
+ Object[] b2 = new Object[1];
+ Object[] b3 = new Object[2];
+
+ Arrays.fill(b1, "1");
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, "1");
+ harness.check(b2[0] == "1");
+
+ Arrays.fill(b3, "1");
+ harness.check(b3[0] == "1");
+ harness.check(b3[1] == "1");
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((Object[]) null, "1");
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(Object[], int, int, long");
+
+ Arrays.fill(b1, 0, 0, "2");
+
+ Arrays.fill(b2, 0, 1, "2");
+ harness.check(b2[0] == "2");
+
+ Arrays.fill(b3, 1, 2, "2");
+ harness.check(b3[0] == "1");
+ harness.check(b3[1] == "2");
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, "2");
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, "2");
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, "2");
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testShort(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(short[], short");
+ short[] b1 = new short[0];
+ short[] b2 = new short[1];
+ short[] b3 = new short[2];
+
+ Arrays.fill(b1, (short) 1);
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, (short) 1);
+ harness.check(b2[0] == 1);
+
+ Arrays.fill(b3, (short) 1);
+ harness.check(b3[0] == 1);
+ harness.check(b3[1] == 1);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((int[]) null, 1);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(short)[], int, int, short");
+
+ Arrays.fill(b1, 0, 0, (short) 2);
+
+ Arrays.fill(b2, 0, 1, (short) 2);
+ harness.check(b2[0] == 2);
+
+ Arrays.fill(b3, 1, 2, (short) 2);
+ harness.check(b3[0] == 1);
+ harness.check(b3[1] == 2);
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, (short) 2);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, (short) 2);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, (short) 2);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+}
+
+}
Index: sort.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/util/Arrays/sort.java,v
retrieving revision 1.2
diff -u -r1.2 sort.java
--- sort.java 3 Feb 2003 13:39:28 -0000 1.2
+++ sort.java 27 Aug 2004 16:15:21 -0000
@@ -1,5 +1,11 @@
// Tags: JDK1.1
+// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
+//
+// [Note: original file had no copyright notice - I've added the following
+// methods: testByte(), testChar(), testDouble(), testFloat(), testInt(),
+// testLong(), testObject() and testShort()]
+
// This file is part of Mauve.
// Mauve is free software; you can redistribute it and/or modify
@@ -18,9 +24,12 @@
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.util.Arrays;
-import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
-import java.util.*;
+import gnu.testlet.Testlet;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Random;
public class sort implements Testlet
{
@@ -63,7 +72,17 @@
}
test_quicksort(harness);
- }
+
+ // these methods added by DG
+ testByte(harness);
+ testChar(harness);
+ testDouble(harness);
+ testFloat(harness);
+ testInt(harness);
+ testLong(harness);
+ testObject(harness);
+ testShort(harness);
+ }
public void test_quicksort(TestHarness harness)
{
@@ -87,4 +106,635 @@
java.util.Arrays.sort(iarray3);
harness.check(isSorted(iarray3));
}
+
+ private void testByte(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.sort(byte[])");
+ byte[] a1 = new byte[] {3, 1, 2};
+ Arrays.sort(a1);
+ harness.check(a1[0] == 1);
+ harness.check(a1[1] == 2);
+ harness.check(a1[2] == 3);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.sort((byte[]) null);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.sort(byte[], int, int)");
+ byte[] a2 = new byte[] {4, 3, 1, 2, 0};
+ Arrays.sort(a2, 1, 4);
+ harness.check(a2[0] == 4);
+ harness.check(a2[1] == 1);
+ harness.check(a2[2] == 2);
+ harness.check(a2[3] == 3);
+ harness.check(a2[4] == 0);
+
+ pass = false;
+ try
+ {
+ Arrays.sort((byte[]) null, 1, 4);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 1, 0);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, -1, 0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 0, 6);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testChar(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.sort(char[])");
+ char[] a1 = new char[] {'3', '1', '2'};
+ Arrays.sort(a1);
+ harness.check(a1[0] == '1');
+ harness.check(a1[1] == '2');
+ harness.check(a1[2] == '3');
+
+ boolean pass = false;
+ try
+ {
+ Arrays.sort((char[]) null);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.sort(char[], int, int)");
+ char[] a2 = new char[] {'4', '3', '1', '2', '0'};
+ Arrays.sort(a2, 1, 4);
+ harness.check(a2[0] == '4');
+ harness.check(a2[1] == '1');
+ harness.check(a2[2] == '2');
+ harness.check(a2[3] == '3');
+ harness.check(a2[4] == '0');
+
+ pass = false;
+ try
+ {
+ Arrays.sort((char[]) null, 1, 4);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 1, 0);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, -1, 0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 0, 6);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testDouble(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.sort(double[])");
+ double[] a1 = new double[] {3, 1, 2};
+ Arrays.sort(a1);
+ harness.check(a1[0] == 1);
+ harness.check(a1[1] == 2);
+ harness.check(a1[2] == 3);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.sort((double[]) null);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.sort(double[], int, int)");
+ double[] a2 = new double[] {4, 3, 1, 2, 0};
+ Arrays.sort(a2, 1, 4);
+ harness.check(a2[0] == 4);
+ harness.check(a2[1] == 1);
+ harness.check(a2[2] == 2);
+ harness.check(a2[3] == 3);
+ harness.check(a2[4] == 0);
+
+ pass = false;
+ try
+ {
+ Arrays.sort((double[]) null, 1, 4);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 1, 0);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, -1, 0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 0, 6);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testFloat(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.sort(float[])");
+ float[] a1 = new float[] {3, 1, 2};
+ Arrays.sort(a1);
+ harness.check(a1[0] == 1);
+ harness.check(a1[1] == 2);
+ harness.check(a1[2] == 3);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.sort((float[]) null);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.sort(float[], int, int)");
+ float[] a2 = new float[] {4, 3, 1, 2, 0};
+ Arrays.sort(a2, 1, 4);
+ harness.check(a2[0] == 4);
+ harness.check(a2[1] == 1);
+ harness.check(a2[2] == 2);
+ harness.check(a2[3] == 3);
+ harness.check(a2[4] == 0);
+
+ pass = false;
+ try
+ {
+ Arrays.sort((float[]) null, 1, 4);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 1, 0);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, -1, 0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 0, 6);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testInt(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.sort(int[])");
+ int[] a1 = new int[] {3, 1, 2};
+ Arrays.sort(a1);
+ harness.check(a1[0] == 1);
+ harness.check(a1[1] == 2);
+ harness.check(a1[2] == 3);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.sort((int[]) null);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.sort(int[], int, int)");
+ int[] a2 = new int[] {4, 3, 1, 2, 0};
+ Arrays.sort(a2, 1, 4);
+ harness.check(a2[0] == 4);
+ harness.check(a2[1] == 1);
+ harness.check(a2[2] == 2);
+ harness.check(a2[3] == 3);
+ harness.check(a2[4] == 0);
+
+ pass = false;
+ try
+ {
+ Arrays.sort((int[]) null, 1, 4);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 1, 0);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, -1, 0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 0, 6);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testLong(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.sort(long[])");
+ long[] a1 = new long[] {3, 1, 2};
+ Arrays.sort(a1);
+ harness.check(a1[0] == 1);
+ harness.check(a1[1] == 2);
+ harness.check(a1[2] == 3);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.sort((long[]) null);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.sort(long[], int, int)");
+ long[] a2 = new long[] {4, 3, 1, 2, 0};
+ Arrays.sort(a2, 1, 4);
+ harness.check(a2[0] == 4);
+ harness.check(a2[1] == 1);
+ harness.check(a2[2] == 2);
+ harness.check(a2[3] == 3);
+ harness.check(a2[4] == 0);
+
+ pass = false;
+ try
+ {
+ Arrays.sort((long[]) null, 1, 4);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 1, 0);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, -1, 0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 0, 6);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testObject(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.sort(Object[])");
+ Object[] a1 = new Object[] {"3", "1", "2"};
+ Arrays.sort(a1);
+ harness.check(a1[0].equals("1"));
+ harness.check(a1[1].equals("2"));
+ harness.check(a1[2].equals("3"));
+
+ boolean pass = false;
+ try
+ {
+ Arrays.sort((Object[]) null);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.sort(Object[], int, int)");
+ Object[] a2 = new Object[] {"4", "3", "1", "2", "0"};
+ Arrays.sort(a2, 1, 4);
+ harness.check(a2[0].equals("4"));
+ harness.check(a2[1].equals("1"));
+ harness.check(a2[2].equals("2"));
+ harness.check(a2[3].equals("3"));
+ harness.check(a2[4].equals("0"));
+
+ pass = false;
+ try
+ {
+ Arrays.sort((Object[]) null, 1, 4);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 1, 0);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, -1, 0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 0, 6);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.sort(Object[], Comparator)");
+ Object[] a3 = new Object[] {"4", "5", "3", "1", "2"};
+ Arrays.sort(a3, (Comparator) null);
+ harness.check(a3[0].equals("1"));
+ harness.check(a3[1].equals("2"));
+ harness.check(a3[2].equals("3"));
+ harness.check(a3[3].equals("4"));
+ harness.check(a3[4].equals("5"));
+ Arrays.sort(a3, new ReverseComparator());
+ harness.check(a3[0].equals("5"));
+ harness.check(a3[1].equals("4"));
+ harness.check(a3[2].equals("3"));
+ harness.check(a3[3].equals("2"));
+ harness.check(a3[4].equals("1"));
+
+ harness.checkPoint("Arrays.sort(Object[], int, int, Comparator)");
+ Object[] a4 = new Object[] {"4", "5", "3", "1", "2"};
+ Arrays.sort(a4, 1, 4, (Comparator) null);
+ harness.check(a4[0].equals("4"));
+ harness.check(a4[1].equals("1"));
+ harness.check(a4[2].equals("3"));
+ harness.check(a4[3].equals("5"));
+ harness.check(a4[4].equals("2"));
+ Arrays.sort(a4, 1, 4, new ReverseComparator());
+ harness.check(a4[0].equals("4"));
+ harness.check(a4[1].equals("5"));
+ harness.check(a4[2].equals("3"));
+ harness.check(a4[3].equals("1"));
+ harness.check(a4[4].equals("2"));
+ }
+
+ private void testShort(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.sort(short[])");
+ short[] a1 = new short[] {3, 1, 2};
+ Arrays.sort(a1);
+ harness.check(a1[0] == 1);
+ harness.check(a1[1] == 2);
+ harness.check(a1[2] == 3);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.sort((short[]) null);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.sort(short[], int, int)");
+ short[] a2 = new short[] {4, 3, 1, 2, 0};
+ Arrays.sort(a2, 1, 4);
+ harness.check(a2[0] == 4);
+ harness.check(a2[1] == 1);
+ harness.check(a2[2] == 2);
+ harness.check(a2[3] == 3);
+ harness.check(a2[4] == 0);
+
+ pass = false;
+ try
+ {
+ Arrays.sort((short[]) null, 1, 4);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 1, 0);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, -1, 0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.sort(a2, 0, 6);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ static class ReverseComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ int i1 = Integer.valueOf(o1.toString()).intValue();
+ int i2 = Integer.valueOf(o2.toString()).intValue();
+ return (i2 - i1);
+ }
+ }
+
}
Index: asList.java
===================================================================
RCS file: asList.java
diff -N asList.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ asList.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,120 @@
+//Tags: JDK1.4
+
+//Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
+
+//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, 59 Temple Place - Suite 330,
+//Boston, MA 02111-1307, USA.
+
+package gnu.testlet.java.util.Arrays;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.List;
+import java.util.RandomAccess;
+
+/**
+ * Some tests for the asList() method in the {@link Arrays} class.
+ */
+public class asList implements Testlet
+{
+
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ Object[] a1 = new Object[] {"1", "2", "3"};
+ List l1 = Arrays.asList(a1);
+
+ // check that the list is the same as the array...
+ harness.check(l1.size() == 3);
+ harness.check(l1.get(0).equals("1"));
+ harness.check(l1.get(1).equals("2"));
+ harness.check(l1.get(2).equals("3"));
+ harness.check(l1 instanceof RandomAccess);
+ harness.check(l1 instanceof Serializable);
+
+ // a change to the list updates the array...
+ l1.set(1, "99");
+ harness.check(a1[1].equals("99"));
+
+ // a change to the array updates the list...
+ a1[1] = "100";
+ harness.check(l1.get(1).equals("100"));
+
+ // check unsupported operations
+ boolean pass = false;
+ try
+ {
+ l1.add("new item");
+ }
+ catch (UnsupportedOperationException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ l1.clear();
+ }
+ catch (UnsupportedOperationException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ try
+ {
+ l1.remove(0);
+ }
+ catch (UnsupportedOperationException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ try
+ {
+ l1.remove("1");
+ }
+ catch (UnsupportedOperationException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // check null argument
+ pass = false;
+ try
+ {
+ Arrays.asList(null);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+}
Index: binarySearch.java
===================================================================
RCS file: binarySearch.java
diff -N binarySearch.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ binarySearch.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,262 @@
+//Tags: JDK1.2
+
+//Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
+
+//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, 59 Temple Place - Suite 330,
+//Boston, MA 02111-1307, USA.
+
+package gnu.testlet.java.util.Arrays;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+/**
+* Some tests for the binarySearch() method in the {@link Arrays} class.
+*/
+public class binarySearch implements Testlet
+{
+
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness) {
+ testByte(harness);
+ testChar(harness);
+ testDouble(harness);
+ testFloat(harness);
+ testInt(harness);
+ testLong(harness);
+ testObject(harness);
+ testShort(harness);
+ }
+
+ private void testByte(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(byte[], byte)");
+ byte[] b1 = new byte[] {1, 2, 3};
+ harness.check(Arrays.binarySearch(b1, (byte) 0) == -1);
+ harness.check(Arrays.binarySearch(b1, (byte) 1) == 0);
+ harness.check(Arrays.binarySearch(b1, (byte) 2) == 1);
+ harness.check(Arrays.binarySearch(b1, (byte) 3) == 2);
+ harness.check(Arrays.binarySearch(b1, (byte) 4) == -4);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch((byte[]) null, (byte) 0);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testChar(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(char[], char)");
+ char[] b1 = new char[] {'1', '2', '3'};
+ harness.check(Arrays.binarySearch(b1, '0') == -1);
+ harness.check(Arrays.binarySearch(b1, '1') == 0);
+ harness.check(Arrays.binarySearch(b1, '2') == 1);
+ harness.check(Arrays.binarySearch(b1, '3') == 2);
+ harness.check(Arrays.binarySearch(b1, '4') == -4);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch((char[]) null, '0');
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testDouble(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(double[], double)");
+ double[] b1 = new double[] {1.0, 2.0, 3.0};
+ harness.check(Arrays.binarySearch(b1, 0.0) == -1);
+ harness.check(Arrays.binarySearch(b1, 1.0) == 0);
+ harness.check(Arrays.binarySearch(b1, 2.0) == 1);
+ harness.check(Arrays.binarySearch(b1, 3.0) == 2);
+ harness.check(Arrays.binarySearch(b1, 4.0) == -4);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch((double[]) null, 0.0);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testFloat(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(float[], float)");
+ float[] b1 = new float[] {1.0f, 2.0f, 3.0f};
+ harness.check(Arrays.binarySearch(b1, 0.0f) == -1);
+ harness.check(Arrays.binarySearch(b1, 1.0f) == 0);
+ harness.check(Arrays.binarySearch(b1, 2.0f) == 1);
+ harness.check(Arrays.binarySearch(b1, 3.0f) == 2);
+ harness.check(Arrays.binarySearch(b1, 4.0f) == -4);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch((float[]) null, 0.0f);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testInt(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(int[], int)");
+ int[] b1 = new int[] {1, 2, 3};
+ harness.check(Arrays.binarySearch(b1, 0) == -1);
+ harness.check(Arrays.binarySearch(b1, 1) == 0);
+ harness.check(Arrays.binarySearch(b1, 2) == 1);
+ harness.check(Arrays.binarySearch(b1, 3) == 2);
+ harness.check(Arrays.binarySearch(b1, 4) == -4);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch((int[]) null, 0);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testLong(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(long[], long)");
+ long[] b1 = new long[] {1, 2, 3};
+ harness.check(Arrays.binarySearch(b1, 0) == -1);
+ harness.check(Arrays.binarySearch(b1, 1) == 0);
+ harness.check(Arrays.binarySearch(b1, 2) == 1);
+ harness.check(Arrays.binarySearch(b1, 3) == 2);
+ harness.check(Arrays.binarySearch(b1, 4) == -4);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch((long[]) null, 0);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testObject(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(Object[], Object)");
+ Object[] b1 = new Object[] {"1", "2", "3"};
+ harness.check(Arrays.binarySearch(b1, "0") == -1);
+ harness.check(Arrays.binarySearch(b1, "1") == 0);
+ harness.check(Arrays.binarySearch(b1, "2") == 1);
+ harness.check(Arrays.binarySearch(b1, "3") == 2);
+ harness.check(Arrays.binarySearch(b1, "4") == -4);
+
+ // searching for null throws NullPointerException
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch(b1, null);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ Arrays.binarySearch((Object[]) null, "0");
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.binarySearch(Object[], Object, Comparator)");
+ harness.check(Arrays.binarySearch(b1, "0", (Comparator) null) == -1);
+ harness.check(Arrays.binarySearch(b1, "1", (Comparator) null) == 0);
+ harness.check(Arrays.binarySearch(b1, "2", (Comparator) null) == 1);
+ harness.check(Arrays.binarySearch(b1, "3", (Comparator) null) == 2);
+ harness.check(Arrays.binarySearch(b1, "4", (Comparator) null) == -4);
+
+ Arrays.sort(b1, new ReverseComparator());
+ harness.check(Arrays.binarySearch(b1, "0", new ReverseComparator()) == -4);
+ harness.check(Arrays.binarySearch(b1, "1", new ReverseComparator()) == 2);
+ harness.check(Arrays.binarySearch(b1, "2", new ReverseComparator()) == 1);
+ harness.check(Arrays.binarySearch(b1, "3", new ReverseComparator()) == 0);
+ harness.check(Arrays.binarySearch(b1, "4", new ReverseComparator()) == -1);
+ }
+
+ private void testShort(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.binarySearch(short[], short)");
+ short[] b1 = new short[] {1, 2, 3};
+ harness.check(Arrays.binarySearch(b1, (short) 0) == -1);
+ harness.check(Arrays.binarySearch(b1, (short) 1) == 0);
+ harness.check(Arrays.binarySearch(b1, (short) 2) == 1);
+ harness.check(Arrays.binarySearch(b1, (short) 3) == 2);
+ harness.check(Arrays.binarySearch(b1, (short) 4) == -4);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.binarySearch((short[]) null, (short) 0);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ static class ReverseComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ int i1 = Integer.valueOf(o1.toString()).intValue();
+ int i2 = Integer.valueOf(o2.toString()).intValue();
+ return (i2 - i1);
+ }
+ }
+
+}
Index: fill.java
===================================================================
RCS file: fill.java
diff -N fill.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ fill.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,728 @@
+//Tags: JDK1.2
+
+//Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
+
+//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, 59 Temple Place - Suite 330,
+//Boston, MA 02111-1307, USA. */
+
+package gnu.testlet.java.util.Arrays;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.util.Arrays;
+
+public class fill implements Testlet
+{
+ public void test (TestHarness harness)
+ {
+ testBoolean(harness);
+ testByte(harness);
+ testChar(harness);
+ testDouble(harness);
+ testFloat(harness);
+ testInt(harness);
+ testLong(harness);
+ testObject(harness);
+ testShort(harness);
+ }
+
+ private void testBoolean(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(boolean[], boolean");
+ boolean[] b1 = new boolean[0];
+ boolean[] b2 = new boolean[1];
+ boolean[] b3 = new boolean[2];
+
+ Arrays.fill(b1, true);
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, true);
+ harness.check(b2[0] == true);
+
+ Arrays.fill(b3, true);
+ harness.check(b3[0] == true);
+ harness.check(b3[1] == true);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((boolean[]) null, true);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(boolean[], int, int, boolean");
+
+ Arrays.fill(b1, 0, 0, false);
+
+ Arrays.fill(b2, 0, 1, false);
+ harness.check(b2[0] == false);
+
+ Arrays.fill(b3, 1, 2, false);
+ harness.check(b3[0] == true);
+ harness.check(b3[1] == false);
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, false);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, false);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testByte(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(byte[], byte");
+ byte[] b1 = new byte[0];
+ byte[] b2 = new byte[1];
+ byte[] b3 = new byte[2];
+
+ Arrays.fill(b1, (byte) 1);
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, (byte) 1);
+ harness.check(b2[0] == (byte) 1);
+
+ Arrays.fill(b3, (byte) 1);
+ harness.check(b3[0] == (byte) 1);
+ harness.check(b3[1] == (byte) 1);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((byte[]) null, (byte) 1);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(byte[], int, int, byte");
+
+ Arrays.fill(b1, 0, 0, (byte) 2);
+
+ Arrays.fill(b2, 0, 1, (byte) 2);
+ harness.check(b2[0] == (byte) 2);
+
+ Arrays.fill(b3, 1, 2, (byte) 2);
+ harness.check(b3[0] == (byte) 1);
+ harness.check(b3[1] == (byte) 2);
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, (byte) 0);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, (byte) 0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, (byte) 0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testChar(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(char[], char");
+ char[] b1 = new char[0];
+ char[] b2 = new char[1];
+ char[] b3 = new char[2];
+
+ Arrays.fill(b1, 'A');
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, 'A');
+ harness.check(b2[0] == 'A');
+
+ Arrays.fill(b3, 'A');
+ harness.check(b3[0] == 'A');
+ harness.check(b3[1] == 'A');
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((char[]) null, 'A');
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(char[], int, int, char");
+
+ Arrays.fill(b1, 0, 0, 'B');
+
+ Arrays.fill(b2, 0, 1, 'B');
+ harness.check(b2[0] == 'B');
+
+ Arrays.fill(b3, 1, 2, 'B');
+ harness.check(b3[0] == 'A');
+ harness.check(b3[1] == 'B');
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, 'B');
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, 'B');
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, 'B');
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testDouble(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(double[], double");
+ double[] b1 = new double[0];
+ double[] b2 = new double[1];
+ double[] b3 = new double[2];
+
+ Arrays.fill(b1, 1.0);
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, 1.0);
+ harness.check(b2[0] == 1.0);
+
+ Arrays.fill(b3, 1.0);
+ harness.check(b3[0] == 1.0);
+ harness.check(b3[1] == 1.0);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((double[]) null, 1.0);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(double[], int, int, double");
+
+ Arrays.fill(b1, 0, 0, 2.0);
+
+ Arrays.fill(b2, 0, 1, 2.0);
+ harness.check(b2[0] == 2.0);
+
+ Arrays.fill(b3, 1, 2, 2.0);
+ harness.check(b3[0] == 1.0);
+ harness.check(b3[1] == 2.0);
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, 2.0);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, 2.0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, 2.0);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testFloat(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(float[], float");
+ float[] b1 = new float[0];
+ float[] b2 = new float[1];
+ float[] b3 = new float[2];
+
+ Arrays.fill(b1, 1.0f);
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, 1.0f);
+ harness.check(b2[0] == 1.0f);
+
+ Arrays.fill(b3, 1.0f);
+ harness.check(b3[0] == 1.0f);
+ harness.check(b3[1] == 1.0f);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((float[]) null, 1.0f);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(float[], int, int, float");
+
+ Arrays.fill(b1, 0, 0, 2.0f);
+
+ Arrays.fill(b2, 0, 1, 2.0f);
+ harness.check(b2[0] == 2.0f);
+
+ Arrays.fill(b3, 1, 2, 2.0f);
+ harness.check(b3[0] == 1.0);
+ harness.check(b3[1] == 2.0);
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, 2.0f);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, 2.0f);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, 2.0f);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testInt(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(int[], int");
+ int[] b1 = new int[0];
+ int[] b2 = new int[1];
+ int[] b3 = new int[2];
+
+ Arrays.fill(b1, 1);
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, 1);
+ harness.check(b2[0] == 1);
+
+ Arrays.fill(b3, 1);
+ harness.check(b3[0] == 1);
+ harness.check(b3[1] == 1);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((int[]) null, 1);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(int[], int, int, int");
+
+ Arrays.fill(b1, 0, 0, 2);
+
+ Arrays.fill(b2, 0, 1, 2);
+ harness.check(b2[0] == 2);
+
+ Arrays.fill(b3, 1, 2, 2);
+ harness.check(b3[0] == 1);
+ harness.check(b3[1] == 2);
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, 2);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, 2);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, 2);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testLong(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(long[], long");
+ long[] b1 = new long[0];
+ long[] b2 = new long[1];
+ long[] b3 = new long[2];
+
+ Arrays.fill(b1, 1);
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, 1);
+ harness.check(b2[0] == 1);
+
+ Arrays.fill(b3, 1);
+ harness.check(b3[0] == 1);
+ harness.check(b3[1] == 1);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((long[]) null, 1);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(long[], int, int, long");
+
+ Arrays.fill(b1, 0, 0, 2);
+
+ Arrays.fill(b2, 0, 1, 2);
+ harness.check(b2[0] == 2);
+
+ Arrays.fill(b3, 1, 2, 2);
+ harness.check(b3[0] == 1);
+ harness.check(b3[1] == 2);
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, 2);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, 2);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, 2);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testObject(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(Object[], Object");
+ Object[] b1 = new Object[0];
+ Object[] b2 = new Object[1];
+ Object[] b3 = new Object[2];
+
+ Arrays.fill(b1, "1");
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, "1");
+ harness.check(b2[0] == "1");
+
+ Arrays.fill(b3, "1");
+ harness.check(b3[0] == "1");
+ harness.check(b3[1] == "1");
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((Object[]) null, "1");
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(Object[], int, int, long");
+
+ Arrays.fill(b1, 0, 0, "2");
+
+ Arrays.fill(b2, 0, 1, "2");
+ harness.check(b2[0] == "2");
+
+ Arrays.fill(b3, 1, 2, "2");
+ harness.check(b3[0] == "1");
+ harness.check(b3[1] == "2");
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, "2");
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, "2");
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, "2");
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ private void testShort(TestHarness harness)
+ {
+ harness.checkPoint("Arrays.fill(short[], short");
+ short[] b1 = new short[0];
+ short[] b2 = new short[1];
+ short[] b3 = new short[2];
+
+ Arrays.fill(b1, (short) 1);
+ harness.check(b1.length == 0);
+
+ Arrays.fill(b2, (short) 1);
+ harness.check(b2[0] == 1);
+
+ Arrays.fill(b3, (short) 1);
+ harness.check(b3[0] == 1);
+ harness.check(b3[1] == 1);
+
+ boolean pass = false;
+ try
+ {
+ Arrays.fill((int[]) null, 1);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ harness.checkPoint("Arrays.fill(short)[], int, int, short");
+
+ Arrays.fill(b1, 0, 0, (short) 2);
+
+ Arrays.fill(b2, 0, 1, (short) 2);
+ harness.check(b2[0] == 2);
+
+ Arrays.fill(b3, 1, 2, (short) 2);
+ harness.check(b3[0] == 1);
+ harness.check(b3[1] == 2);
+
+ // from index should be <= toIndex
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 2, 1, (short) 2);
+ }
+ catch (IllegalArgumentException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // from index should be >= 0
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, -1, 1, (short) 2);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // to index should be < array.length
+ pass = false;
+ try
+ {
+ Arrays.fill(b3, 0, 4, (short) 2);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+}
+
+}