Fixed unit tests.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@2006 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2006-12-21 19:53:36 +00:00
parent 5d9c17a853
commit 25ecb66363
2 changed files with 35 additions and 23 deletions
+4 -1
View File
@@ -44,7 +44,7 @@
</target>
<!-- build the java class files -->
<target name="compile" depends="prepare">
<target name="compile" depends="prepare,compute-builds">
<javac srcdir="${src.dir}" destdir="${deploy.dir}/classes"
debug="on" optimize="off" deprecation="off">
<classpath refid="classpath"/>
@@ -58,6 +58,9 @@
<exclude name="com/samskivert/util/**" unless="build.util"/>
<exclude name="com/samskivert/velocity/**" unless="build.velocity"/>
<exclude name="com/samskivert/xml/**" unless="build.xml"/>
<compilerarg value="-Xlint"/>
<compilerarg value="-Xlint:-serial"/>
<compilerarg value="-Xlint:-deprecation"/>
</javac>
</target>
@@ -21,6 +21,8 @@
package com.samskivert.util;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -34,31 +36,23 @@ public class HashIntMapTest extends TestCase
public void runTest ()
{
HashIntMap table = new HashIntMap();
HashIntMap<Integer> table = new HashIntMap<Integer>();
populateTable(table);
// check the table contents
for (int i = 10; i < 20; i++) {
Integer val = (Integer)table.get(i);
Integer val = table.get(i);
assertTrue("get(" + i + ") == " + i, val.intValue() == i);
}
String keys = StringUtil.toString(table.keys());
assertTrue("keys valid", keys.equals(TEST1));
String elems = StringUtil.toString(table.elements());
assertTrue("elems valid", elems.equals(TEST1));
checkContents(table, TEST1, TEST1);
// remove some entries and attempt to remove some non-entries
for (int i = 12; i < 22; i++) {
table.remove(i);
}
keys = StringUtil.toString(table.keys());
assertTrue("keys valid", keys.equals(TEST2));
elems = StringUtil.toString(table.elements());
assertTrue("elems valid", elems.equals(TEST2));
checkContents(table, TEST2, TEST2);
// now try some serialization
populateTable(table);
@@ -73,11 +67,12 @@ public class HashIntMapTest extends TestCase
FileInputStream fin = new FileInputStream(tmpfile);
ObjectInputStream in = new ObjectInputStream(fin);
HashIntMap map = (HashIntMap)in.readObject();
@SuppressWarnings("unchecked") HashIntMap<Integer> map =
(HashIntMap<Integer>)in.readObject();
// check the table contents
for (int i = 10; i < 20; i++) {
Integer val = (Integer)table.get(i);
Integer val = table.get(i);
assertTrue("get(" + i + ") == " + i, val.intValue() == i);
}
@@ -100,23 +95,23 @@ public class HashIntMapTest extends TestCase
Integer val;
// let's keep the ones that are a multiple of 16
if ((ii & 15) == 0) {
val = (Integer) table.get(ii);
val = table.get(ii);
} else {
val = (Integer) table.remove(ii);
val = table.remove(ii);
}
assertTrue("get(" + ii + ") == " + val, val.intValue() == ii);
}
// and then let's also remove the multiples of 16
for (int ii=1; ii < 12345; ii += 3) {
for (int ii = 1; ii < 12345; ii += 3) {
if ((ii & 15) == 0) {
Integer val = (Integer) table.remove(ii);
Integer val = table.remove(ii);
assertTrue("get(" + ii + ") == " + val, val.intValue() == ii);
}
}
}
protected void populateTable (HashIntMap table)
protected void populateTable (HashIntMap<Integer> table)
{
for (int i = 10; i < 20; i++) {
Integer value = new Integer(i);
@@ -124,12 +119,26 @@ public class HashIntMapTest extends TestCase
}
}
protected void checkContents (HashIntMap<Integer> table, String exkeys, String exvals)
{
ArrayList<Integer> keys = new ArrayList<Integer>();
keys.addAll(table.keySet());
Collections.sort(keys);
String keystr = StringUtil.toString(keys);
assertTrue(keystr + ".equals(" + exkeys + ")", keystr.equals(exkeys));
ArrayList<Integer> values = new ArrayList<Integer>();
values.addAll(table.values());
Collections.sort(values);
String valuestr = StringUtil.toString(values);
assertTrue(valuestr + ".equals(" + exvals + ")", valuestr.equals(exvals));
}
public static Test suite ()
{
return new HashIntMapTest();
}
protected static final String TEST1 =
"(15, 16, 14, 19, 11, 18, 12, 17, 13, 10)";
protected static final String TEST2 = "(11, 10)";
protected static final String TEST1 = "(10, 11, 12, 13, 14, 15, 16, 17, 18, 19)";
protected static final String TEST2 = "(10, 11)";
}