Sets
public void testContainsNonExisting() { assertFalse(_set.contains(E)); assertFalse(_set.contains(F));
}
The testAddNewKey() method first checks the initial size of the set before adding two values. Each time add() is called, the return value is checked to ensure it is true, indicating there was no existing value; contains() is then called to ensure that the new value exists, and the size is checked to ensure it has increased by one:
public void testAddNewValue() { assertEquals(4, _set.size());
assertTrue(_set.add(E)); assertTrue(_set.contains(E)); assertEquals(5, _set.size());
assertTrue(_set.add(F)); assertTrue(_set.contains(F)); assertEquals(6, _set.size());
}
The method testAddExistingValueHasNoEffect() simply attempts to add all the values again. Each time a duplicate is added, the return value and size are checked to ensure that the call has had no effect:
public void testAddExistingValueHasNoEffect() { assertEquals(4, _set.size());
assertFalse(_set.add(A)); assertEquals(4, _set.size());
assertFalse(_set.add(B)); assertEquals(4, _set.size());
assertFalse(_set.add(C)); assertEquals(4, _set.size());
assertFalse(_set.add(D)); assertEquals(4, _set.size());
}
Next, testDeleteExisting() removes each of the four values that were used to populate the set initially. Each time delete() is called, the return value and size of the set are checked to ensure they reflect the deletion:
public void testDeleteExisting() { assertEquals(4, _set.size());
assertTrue(_set.delete(B)); assertFalse(_set.contains(B)); assertEquals(3, _set.size());
assertTrue(_set.delete(A));