Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
espertus committed May 29, 2023
1 parent ae49f5e commit 530ed77
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}

dependencies {
implementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
}

test {
useJUnitPlatform()
}
31 changes: 31 additions & 0 deletions src/test/java/HashSetTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class HashSetTest {

@Test
public void testIntegersNoCollisions() {
HashSet<Integer> set = new HashSet<>(10);
set.add(1);
set.add(2);
assertTrue(set.contains(1));
assertTrue(set.contains(2));
assertFalse(set.contains(0));
// hashCode() of an int is that int
assertEquals(0, set.getNumCollisions());
}

@Test
public void testIntegersWithCollisions() {
HashSet<Integer> set = new HashSet<>(10);
set.add(1);
set.add(2);
set.add(11);
assertTrue(set.contains(1));
assertTrue(set.contains(2));
assertTrue(set.contains(11)); // collides with 1
assertFalse(set.contains(0));
assertEquals(1, set.getNumCollisions());
}
}

0 comments on commit 530ed77

Please sign in to comment.