Skip to content

Commit 123c8cc

Browse files
committed
test: add test for Tombstone::equals
Changed signature of HashSet::tombstone to allow for testing.
1 parent 63f4f39 commit 123c8cc

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/main/java/dataStructures/hashSet/openAddressing/HashSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ private boolean isLoadFactorExceeded() {
318318
return this.size() >= this.capacity() * LOAD_FACTOR;
319319
}
320320

321-
private static <T> T tombstone() {
321+
public T tombstone() {
322322
// It is safe to cast Tombstone to T, because methods retrieving elements (HashSet::get) from the HashSet
323323
// should, and will check whether the item is a Tombstone object, returning null in-place of the Tombstone.
324324
@SuppressWarnings("unchecked")

src/test/java/dataStructures/hashSet/openAddressing/HashSetTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertNotEquals;
56
import static org.junit.Assert.assertTrue;
67

78
import java.util.List;
@@ -137,4 +138,20 @@ public void testAdd_afterRemove() {
137138

138139
assertEquals(expectedList, actualList);
139140
}
141+
142+
@Test
143+
public void testTombstoneEquals() {
144+
HashSet<Integer> integerHashSet = new HashSet<>();
145+
assertNotEquals(Integer.valueOf(5), integerHashSet.tombstone());
146+
assertNotEquals(null, integerHashSet.tombstone());
147+
148+
HashSet<Boolean> booleanHashSet = new HashSet<>();
149+
assertNotEquals(Boolean.TRUE, booleanHashSet.tombstone());
150+
assertNotEquals(Boolean.FALSE, booleanHashSet.tombstone());
151+
assertNotEquals(null, booleanHashSet.tombstone());
152+
153+
HashSet<Object> objectHashSet = new HashSet<>();
154+
assertNotEquals(new Object(), objectHashSet.tombstone());
155+
assertNotEquals(null, objectHashSet.tombstone());
156+
}
140157
}

0 commit comments

Comments
 (0)