File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
test/dataStructures/hashSet/openAddressing Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 4
4
import src .dataStructures .hashSet .openAddressing .HashSet ;
5
5
6
6
import java .util .List ;
7
+ import java .util .stream .Collectors ;
7
8
import java .util .stream .Stream ;
8
9
9
10
import static org .junit .Assert .*;
@@ -109,4 +110,25 @@ public void testResize() {
109
110
// Verify that the HashSet has resized and halved its capacity back to 16.
110
111
assertEquals (16 , set .capacity ());
111
112
}
113
+
114
+ @ Test
115
+ public void testAdd_afterRemove () {
116
+ HashSet <Integer > hashSet = new HashSet <>();
117
+ // these elements all map to the same initial bucket, resulting in collisions.
118
+ hashSet .add (1 );
119
+ hashSet .add (17 );
120
+ hashSet .add (33 );
121
+ // the hashSet will look like {1, 17, 33, ...} after the series of adds
122
+
123
+ hashSet .remove (17 );
124
+ // hashSet now looks like {1, X, 33, ...} where X denotes a tombstone.
125
+
126
+ boolean isAdded = hashSet .add (33 ); // this should not be added into the hashSet.
127
+ assertFalse (isAdded );
128
+
129
+ List <Integer > expectedList = List .of (1 , 33 );
130
+ List <Integer > actualList = hashSet .toList ();
131
+
132
+ assertEquals (expectedList , actualList );
133
+ }
112
134
}
You can’t perform that action at this time.
0 commit comments