You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2020/04/27 20:45:37 UTC

[incubator-datasketches-java] 01/01: Improve test coverage using Clover.

This is an automated email from the ASF dual-hosted git repository.

leerho pushed a commit to branch ImproveTestCoverage
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-java.git

commit f4a3362582376652672985c5fcc0b496c6b2c780
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Mon Apr 27 13:45:00 2020 -0700

    Improve test coverage using Clover.
---
 .../org/apache/datasketches/cpc/BitMatrix.java     |  6 +++---
 .../datasketches/sampling/VarOptItemsSketch.java   | 24 ++++++++++++++++++----
 .../org/apache/datasketches/cpc/TestAllTest.java   | 22 +++++++++++++++++++-
 .../sampling/VarOptItemsSketchTest.java            |  8 +++-----
 4 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/cpc/BitMatrix.java b/src/main/java/org/apache/datasketches/cpc/BitMatrix.java
index 9b5c50b..8f88ad9 100644
--- a/src/main/java/org/apache/datasketches/cpc/BitMatrix.java
+++ b/src/main/java/org/apache/datasketches/cpc/BitMatrix.java
@@ -57,7 +57,8 @@ class BitMatrix {
 
   long getNumCoupons() {
     if (numCouponsInvalid) {
-      numCoupons = countCoupons();
+      numCoupons = countCoupons(bitMatrix);
+      numCouponsInvalid = false;
     }
     return numCoupons;
   }
@@ -98,11 +99,10 @@ class BitMatrix {
     }
   }
 
-  private long countCoupons() {
+  static long countCoupons(final long[] bitMatrix) {
     long count = 0;
     final int len = bitMatrix.length;
     for (int i = 0; i < len; i++) { count += Long.bitCount(bitMatrix[i]); }
-    numCouponsInvalid = false;
     return count;
   }
 
diff --git a/src/main/java/org/apache/datasketches/sampling/VarOptItemsSketch.java b/src/main/java/org/apache/datasketches/sampling/VarOptItemsSketch.java
index 54d69ab..055ebbb 100644
--- a/src/main/java/org/apache/datasketches/sampling/VarOptItemsSketch.java
+++ b/src/main/java/org/apache/datasketches/sampling/VarOptItemsSketch.java
@@ -20,7 +20,23 @@
 package org.apache.datasketches.sampling;
 
 import static org.apache.datasketches.Util.LS;
-import static org.apache.datasketches.sampling.PreambleUtil.*;
+import static org.apache.datasketches.sampling.PreambleUtil.EMPTY_FLAG_MASK;
+import static org.apache.datasketches.sampling.PreambleUtil.GADGET_FLAG_MASK;
+import static org.apache.datasketches.sampling.PreambleUtil.SER_VER;
+import static org.apache.datasketches.sampling.PreambleUtil.TOTAL_WEIGHT_R_DOUBLE;
+import static org.apache.datasketches.sampling.PreambleUtil.VO_PRELONGS_EMPTY;
+import static org.apache.datasketches.sampling.PreambleUtil.VO_PRELONGS_FULL;
+import static org.apache.datasketches.sampling.PreambleUtil.VO_PRELONGS_WARMUP;
+import static org.apache.datasketches.sampling.PreambleUtil.extractFamilyID;
+import static org.apache.datasketches.sampling.PreambleUtil.extractFlags;
+import static org.apache.datasketches.sampling.PreambleUtil.extractHRegionItemCount;
+import static org.apache.datasketches.sampling.PreambleUtil.extractK;
+import static org.apache.datasketches.sampling.PreambleUtil.extractN;
+import static org.apache.datasketches.sampling.PreambleUtil.extractRRegionItemCount;
+import static org.apache.datasketches.sampling.PreambleUtil.extractResizeFactor;
+import static org.apache.datasketches.sampling.PreambleUtil.extractSerVer;
+import static org.apache.datasketches.sampling.PreambleUtil.extractTotalRWeight;
+import static org.apache.datasketches.sampling.PreambleUtil.getAndCheckPreLongs;
 import static org.apache.datasketches.sampling.SamplingUtil.pseudoHypergeometricLBonP;
 import static org.apache.datasketches.sampling.SamplingUtil.pseudoHypergeometricUBonP;
 
@@ -105,7 +121,7 @@ public final class VarOptItemsSketch<T> {
 
   private VarOptItemsSketch(final int k, final ResizeFactor rf) {
     // required due to a theorem about lightness during merging
-    if (k < 1 || k > (Integer.MAX_VALUE - 1)) {
+    if ((k < 1) || (k > (Integer.MAX_VALUE - 1))) {
       throw new SketchesArgumentException("k must be at least 1 and less than " + Integer.MAX_VALUE
         + ". Found: " + k);
     }
@@ -271,8 +287,8 @@ public final class VarOptItemsSketch<T> {
                 + " for an empty sketch. Found: " + numPreLongs);
       }
     } else {
-      if (numPreLongs != VO_PRELONGS_WARMUP
-          && numPreLongs != VO_PRELONGS_FULL) {
+      if ((numPreLongs != VO_PRELONGS_WARMUP)
+          && (numPreLongs != VO_PRELONGS_FULL)) {
         throw new SketchesArgumentException("Possible corruption: Must be " + VO_PRELONGS_WARMUP
                 + " or " + VO_PRELONGS_FULL + " for a non-empty sketch. Found: " + numPreLongs);
       }
diff --git a/src/test/java/org/apache/datasketches/cpc/TestAllTest.java b/src/test/java/org/apache/datasketches/cpc/TestAllTest.java
index d09db5b..a6d1453 100644
--- a/src/test/java/org/apache/datasketches/cpc/TestAllTest.java
+++ b/src/test/java/org/apache/datasketches/cpc/TestAllTest.java
@@ -20,9 +20,11 @@
 package org.apache.datasketches.cpc;
 
 import static org.apache.datasketches.Util.DEFAULT_UPDATE_SEED;
+import static org.testng.Assert.assertEquals;
 
 import java.io.PrintStream;
 import java.io.PrintWriter;
+import java.util.Arrays;
 
 import org.testng.annotations.Test;
 
@@ -49,6 +51,18 @@ public class TestAllTest {
     sVal.start();
   }
 
+  //Matrix
+  @Test
+  public void matrixCouponCountCheck() {
+    long pat = 0xA5A5A5A5_5A5A5A5AL;
+    int len = 16;
+    long[] arr = new long[len];
+    Arrays.fill(arr, pat);
+    long trueCount = len * Long.bitCount(pat);
+    long testCount = BitMatrix.countCoupons(arr);
+    assertEquals(testCount, trueCount);
+  }
+
   //COMPRESSION
 
   @Test //scope = Test
@@ -82,7 +96,7 @@ public class TestAllTest {
 
   //MERGING
 
-  //@Test //longer test. use for characterization
+  @Test //longer test. use for characterization
   public void mergingValidationCheck() {
     int lgMinK = 10;
     int lgMaxK = 10; //inclusive
@@ -106,4 +120,10 @@ public class TestAllTest {
     qmv.start();
   }
 
+  @Test
+  public void checkPwrLaw10NextDouble() {
+    double next = TestUtil.pwrLaw10NextDouble(1, 10.0);
+    assertEquals(next, 100.0);
+  }
+
 }
diff --git a/src/test/java/org/apache/datasketches/sampling/VarOptItemsSketchTest.java b/src/test/java/org/apache/datasketches/sampling/VarOptItemsSketchTest.java
index f06d626..4454308 100644
--- a/src/test/java/org/apache/datasketches/sampling/VarOptItemsSketchTest.java
+++ b/src/test/java/org/apache/datasketches/sampling/VarOptItemsSketchTest.java
@@ -23,21 +23,19 @@ import static org.apache.datasketches.sampling.PreambleUtil.FAMILY_BYTE;
 import static org.apache.datasketches.sampling.PreambleUtil.PREAMBLE_LONGS_BYTE;
 import static org.apache.datasketches.sampling.PreambleUtil.SER_VER_BYTE;
 import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
-import org.testng.annotations.Test;
-
-import org.apache.datasketches.memory.Memory;
-import org.apache.datasketches.memory.WritableMemory;
 import org.apache.datasketches.ArrayOfLongsSerDe;
 import org.apache.datasketches.ArrayOfStringsSerDe;
 import org.apache.datasketches.Family;
 import org.apache.datasketches.ResizeFactor;
 import org.apache.datasketches.SketchesArgumentException;
 import org.apache.datasketches.SketchesStateException;
+import org.apache.datasketches.memory.Memory;
+import org.apache.datasketches.memory.WritableMemory;
+import org.testng.annotations.Test;
 
 @SuppressWarnings("javadoc")
 public class VarOptItemsSketchTest {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org