Use Arrays.equals() instead of rolling our own.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@558 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2002-02-03 07:09:50 +00:00
parent fa448571ca
commit 1b26bab85b
@@ -1,5 +1,5 @@
//
// $Id: IntListUtilTest.java,v 1.2 2001/12/13 01:31:23 mdb Exp $
// $Id: IntListUtilTest.java,v 1.3 2002/02/03 07:09:50 mdb Exp $
//
// samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne
@@ -20,6 +20,8 @@
package com.samskivert.util;
import java.util.Arrays;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -38,15 +40,15 @@ public class IntListUtilTest extends TestCase
list = IntListUtil.add(list, 2);
// System.out.println("add(2): " + StringUtil.toString(list));
assert("add(2)", arraysEqual(list, new int[] { 2, 0, 0, 0 }));
assert("add(2)", Arrays.equals(list, new int[] { 2, 0, 0, 0 }));
list = IntListUtil.add(list, 5);
// System.out.println("add(5): " + StringUtil.toString(list));
assert("add(5)", arraysEqual(list, new int[] { 2, 5, 0, 0 }));
assert("add(5)", Arrays.equals(list, new int[] { 2, 5, 0, 0 }));
IntListUtil.clear(list, 2);
// System.out.println("clear(2): " + StringUtil.toString(list));
assert("clear(2)", arraysEqual(list, new int[] { 0, 5, 0, 0 }));
assert("clear(2)", Arrays.equals(list, new int[] { 0, 5, 0, 0 }));
boolean contains5 = IntListUtil.contains(list, 5);
// System.out.println("contains(newBar): " + contains5);
@@ -54,18 +56,18 @@ public class IntListUtilTest extends TestCase
IntListUtil.removeAt(list, 1);
// System.out.println("removeAt(1): " + StringUtil.toString(list));
assert("removeAt(1)", arraysEqual(list, new int[] { 0, 0, 0, 0 }));
assert("removeAt(1)", Arrays.equals(list, new int[] { 0, 0, 0, 0 }));
list = IntListUtil.add(list, 0, 2);
list = IntListUtil.add(list, 1, 5);
// System.out.println("add(0, 2) + add(1, 5): " +
// StringUtil.toString(list));
assert("add(0, 2) + add(1, 5))",
arraysEqual(list, new int[] { 2, 5, 0, 0 }));
Arrays.equals(list, new int[] { 2, 5, 0, 0 }));
IntListUtil.remove(list, 2);
// System.out.println("remove(2): " + StringUtil.toString(list));
assert("removeAt(2)", arraysEqual(list, new int[] { 5, 0, 0, 0 }));
assert("removeAt(2)", Arrays.equals(list, new int[] { 5, 0, 0, 0 }));
list = IntListUtil.add(list, 0, 2);
list = IntListUtil.add(list, 1, 5);
@@ -73,11 +75,11 @@ public class IntListUtilTest extends TestCase
// System.out.println("add(0, 2) + add(1, 5) + add(2, 6): " +
// StringUtil.toString(list));
assert("add(0, 2) + add(1, 5) + add(2, 6)",
arraysEqual(list, new int[] { 5, 2, 5, 6 }));
Arrays.equals(list, new int[] { 5, 2, 5, 6 }));
IntListUtil.removeAt(list, 0);
// System.out.println("removeAt(0): " + StringUtil.toString(list));
assert("removeAt(0)", arraysEqual(list, new int[] { 2, 5, 6, 0 }));
assert("removeAt(0)", Arrays.equals(list, new int[] { 2, 5, 6, 0 }));
int[] tl = IntListUtil.testAndAdd(list, 5);
// if (tl == null) {
@@ -103,22 +105,7 @@ public class IntListUtilTest extends TestCase
IntListUtil.removeAt(list, 0);
// System.out.println("removeAt(0): " + StringUtil.toString(list));
assert("removeAt(0)", arraysEqual(list, new int[] { 5, 6, 7, 0 }));
}
protected boolean arraysEqual (int[] a1, int[] a2)
{
if (a1.length != a2.length) {
return false;
}
for (int i = 0; i < a1.length; i++) {
if (a1[i] != a2[i]) {
return false;
}
}
return true;
assert("removeAt(0)", Arrays.equals(list, new int[] { 5, 6, 7, 0 }));
}
public static Test suite ()