rendered paste bodypackage tests;
import java.util.HashSet;
import junit.framework.TestCase;
public class EqualTests extends TestCase {
public EqualTests(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void testHashset() throws Exception {
someObj[] o1 = {
new someObj("a"),
new someObj("bb"),
new someObj("ccc")
};
someObj[] o2 = {
new someObj("a"),
new someObj("bb"),
new someObj("ccc")
};
HashSet s1 = new HashSet(5);
for(someObj o : o1)
s1.add(o);
HashSet s2 = new HashSet(5);
for(someObj o : o2)
s2.add(o);
System.out.println(s1);
System.out.println(s2);
assertTrue(s1.equals(s2));
}
private class someObj {
String value;
public someObj(String s) {
value = s;
}
public int hashCode() {
return value.length();
}
public boolean equals(someObj o) {
return this.value.equals(o.value);
}
public int compareTo(someObj o) {
return this.value.compareTo(o.value);
}
public String toString() {
return value;
}
}
}