Several TAs were having trouble parsing the castling tests and the equality tests.
We should review these and see if they can be simplified.
@Test
@DisplayName("HashCode Testing")
public void hashTest() {
Assertions.assertEquals(original.hashCode(), equivalent.hashCode(),
className + ".hashCode() returned different values for equivalent " + itemsPlural);
for (var different : allDifferent) {
Assertions.assertNotEquals(original.hashCode(), different.hashCode(),
className + ".hashCode() returned the same value for different " + itemsPlural);
}
}
@Test
@DisplayName("Equals & HashCode Testing")
public void hashSetTest() {
Set<T> set = new HashSet<>();
set.add(original);
// Manually test insertion of original & equal items
Assertions.assertTrue(set.contains(original),
"[" + className + "] Original item should exist in collection after adding original item");
Assertions.assertTrue(set.contains(equivalent),
"[" + className + "] Equivalent item should exist in collection after only adding original item");
Assertions.assertEquals(1, set.size(),
"[" + className + "] Collection should contain only 1 item after a single insert");
set.add(equivalent);
Assertions.assertEquals(1, set.size(),
"[" + className + "] Collection should still contain only 1 item after adding equivalent item");
// Programmatically test insertion of all different items
int expectedSetSize = 1;
for (var different : allDifferent) {
Assertions.assertFalse(set.contains(different),
"[" + className + "] Different item should not be present in set before insertion");
set.add(different);
expectedSetSize++;
Assertions.assertEquals(expectedSetSize, set.size(),
"[" + className + "] New item was counted as different during insertion");
}
}
Several TAs were having trouble parsing the castling tests and the equality tests.
We should review these and see if they can be simplified.