File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -8,3 +8,11 @@ version '1.0-SNAPSHOT'
88repositories {
99 mavenCentral()
1010}
11+
12+ dependencies {
13+ implementation ' org.junit.jupiter:junit-jupiter-api:5.8.1'
14+ }
15+
16+ test {
17+ useJUnitPlatform()
18+ }
Original file line number Diff line number Diff line change 1+ import org .junit .jupiter .api .Test ;
2+
3+ import static org .junit .jupiter .api .Assertions .*;
4+
5+ public class HashSetTest {
6+
7+ @ Test
8+ public void testIntegersNoCollisions () {
9+ HashSet <Integer > set = new HashSet <>(10 );
10+ set .add (1 );
11+ set .add (2 );
12+ assertTrue (set .contains (1 ));
13+ assertTrue (set .contains (2 ));
14+ assertFalse (set .contains (0 ));
15+ // hashCode() of an int is that int
16+ assertEquals (0 , set .getNumCollisions ());
17+ }
18+
19+ @ Test
20+ public void testIntegersWithCollisions () {
21+ HashSet <Integer > set = new HashSet <>(10 );
22+ set .add (1 );
23+ set .add (2 );
24+ set .add (11 );
25+ assertTrue (set .contains (1 ));
26+ assertTrue (set .contains (2 ));
27+ assertTrue (set .contains (11 )); // collides with 1
28+ assertFalse (set .contains (0 ));
29+ assertEquals (1 , set .getNumCollisions ());
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments