/** java.util.FastSet#add(java.lang.Object) */ public void test_addLjava_lang_Object() { // Test for method boolean java.util.FastSet.add(java.lang.Object) int size = hs.size(); hs.add(new Integer(8)); assertTrue("Added element already contained by set", hs.size() == size); hs.add(new Integer(-9)); assertTrue("Failed to increment set size after add", hs.size() == size + 1); assertTrue("Failed to add element to set", hs.contains(new Integer(-9))); }
/** java.util.FastSet#remove(java.lang.Object) */ public void test_removeLjava_lang_Object() { // Test for method boolean java.util.FastSet.remove(java.lang.Object) int size = hs.size(); hs.remove(new Integer(98)); assertTrue("Failed to remove element", !hs.contains(new Integer(98))); assertTrue("Failed to decrement set size", hs.size() == size - 1); SlimSet s = new SlimSet(); s.add(null); assertTrue("Cannot handle null", s.remove(null)); assertFalse(hs.remove(new Integer(-98))); }
/** java.util.FastSet#clear() */ public void test_clear() { // Test for method void java.util.FastSet.clear() Set orgSet = (Set) hs.clone(); hs.clear(); Iterator i = orgSet.iterator(); assertEquals("Returned non-zero size after clear", 0, hs.size()); while (i.hasNext()) { assertTrue("Failed to clear set", !hs.contains(i.next())); } }
/** java.util.FastSet#FastSet(int, float) */ public void test_ConstructorIF() { // Test for method java.util.FastSet(int, float) SlimSet hs2 = new SlimSet(5, (float) 0.5); assertEquals("Created incorrect FastSet", 0, hs2.size()); try { new SlimSet(0, 0); } catch (IllegalArgumentException e) { return; } fail("Failed to throw IllegalArgumentException for initial load factor <= 0"); }
/** java.util.FastSet#iterator() */ public void test_iterator() { // Test for method java.util.Iterator java.util.FastSet.iterator() Iterator i = hs.iterator(); int x = 0; while (i.hasNext()) { assertTrue("Failed to iterate over all elements", hs.contains(i.next())); ++x; } assertTrue("Returned iteration of incorrect size", hs.size() == x); SlimSet s = new SlimSet(); s.add(null); assertNull("Cannot handle null", s.iterator().next()); }
/** java.util.FastSet#FastSet(java.util.Collection) */ public void test_ConstructorLjava_util_Collection() { // Test for method java.util.FastSet(java.util.Collection) SlimSet hs2 = new SlimSet(Arrays.asList(objArray)); for (int counter = 0; counter < objArray.length; counter++) { assertTrue("FastSet does not contain correct elements", hs.contains(objArray[counter])); } assertTrue("FastSet created from collection incorrect size", hs2.size() == objArray.length); try { new SlimSet((Collection) null); fail("NullPointerException expected"); } catch (NullPointerException e) { // expected } }
/** java.util.FastSet#FastSet(int) */ public void test_ConstructorI() { // Test for method java.util.FastSet(int) SlimSet hs2 = new SlimSet(5); assertEquals("Created incorrect FastSet", 0, hs2.size()); }
/** java.util.FastSet#size() */ public void test_size() { // Test for method int java.util.FastSet.size() assertTrue("Returned incorrect size", hs.size() == (objArray.length + 1)); hs.clear(); assertEquals("Cleared set returned non-zero size", 0, hs.size()); }