From 2484576920f7e3aff55044524d53e7b3455c93d7 Mon Sep 17 00:00:00 2001 From: Lee Rhodes Date: Tue, 3 May 2016 16:02:53 -0700 Subject: [PATCH] added unit tests --- .../yahoo/sketches/BinomialBoundsNTest.java | 20 ++++++++++++++++++ .../yahoo/sketches/HashOperationsTest.java | 21 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/test/java/com/yahoo/sketches/BinomialBoundsNTest.java b/src/test/java/com/yahoo/sketches/BinomialBoundsNTest.java index 1cc9d43fa..375a35e5d 100644 --- a/src/test/java/com/yahoo/sketches/BinomialBoundsNTest.java +++ b/src/test/java/com/yahoo/sketches/BinomialBoundsNTest.java @@ -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; @@ -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()); diff --git a/src/test/java/com/yahoo/sketches/HashOperationsTest.java b/src/test/java/com/yahoo/sketches/HashOperationsTest.java index 27e783e4c..d0a7d3127 100644 --- a/src/test/java/com/yahoo/sketches/HashOperationsTest.java +++ b/src/test/java/com/yahoo/sketches/HashOperationsTest.java @@ -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; @@ -35,6 +36,7 @@ public void testHashCorruption() { @Test(expectedExceptions = IllegalStateException.class) public void testHashAndThetaCorruption1() { + checkHashAndThetaCorruption(1, 1); //pass checkHashAndThetaCorruption(0, 0); //theta = 0 fails } @@ -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;