Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Rhodes committed May 3, 2016
1 parent b5ad81d commit 2484576
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/test/java/com/yahoo/sketches/BinomialBoundsNTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import static com.yahoo.sketches.BinomialBoundsN.*;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;

import org.testng.annotations.Test;
Expand Down Expand Up @@ -114,6 +115,25 @@ public void checkCheckArgs() {
}
}

@Test
public void checkComputeApproxBino_LB_UB() {
long n = 100;
double theta = (2.0 - 1e-5)/2.0;
double result = getLowerBound(n, theta, 1, false);
assertEquals(result, n, 0.0);
result = getUpperBound(n, theta, 1, false);
assertEquals(result, n+1, 0.0);
result = getLowerBound(n, theta, 1, true);
assertEquals(result, 0.0, 0.0);
result = getUpperBound(n, theta, 1, true);
assertEquals(result, 0.0, 0.0);
}

@Test(expectedExceptions = IllegalArgumentException.class)
public void checkThetaLimits1() {
BinomialBoundsN.getUpperBound(100, 1.1, 1, false);
}

@Test
public void printlnTest() {
println("PRINTING: "+this.getClass().getName());
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/yahoo/sketches/HashOperationsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.testng.annotations.Test;

import static com.yahoo.sketches.hash.MurmurHash3.*;
import com.yahoo.sketches.memory.Memory;
import com.yahoo.sketches.memory.NativeMemory;

Expand All @@ -35,6 +36,7 @@ public void testHashCorruption() {

@Test(expectedExceptions = IllegalStateException.class)
public void testHashAndThetaCorruption1() {
checkHashAndThetaCorruption(1, 1); //pass
checkHashAndThetaCorruption(0, 0); //theta = 0 fails
}

Expand All @@ -48,6 +50,25 @@ public void testHashAndThetaCorruption3() {
checkHashAndThetaCorruption(1, -1); //hash = -1 fails
}

@Test(expectedExceptions = IllegalArgumentException.class)
public void checkHashSearch() {
hashSearch(new long[4], 2, 0);
}

@Test
public void checkHashArrayInsert() {
long[] hTable = new long[16];
long[] hashIn = new long[1];
for (int i=0; i<8; i++) {
hashIn[0] = i;
long h = hash(hashIn, 0)[0] >>> 1;
hashInsertOnly(hTable, 4, h);
int count = hashArrayInsert(hTable, hTable, 4, Long.MAX_VALUE);
assertEquals(count, 0);
}

}

@Test
public void testContinueCondtion() {
long thetaLong = Long.MAX_VALUE/2;
Expand Down

0 comments on commit 2484576

Please sign in to comment.