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/07/07 23:37:13 UTC
[incubator-datasketches-java] 10/10: Add unit tests
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch Refactor_Theta_Tuple
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-java.git
commit 644ab859645efce4fb14665533117edbed17bf16
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Tue Jul 7 16:35:03 2020 -0700
Add unit tests
---
.../apache/datasketches/theta/IntersectionImpl.java | 6 +-----
.../apache/datasketches/theta/IntersectionImplR.java | 18 +++++++++---------
.../org/apache/datasketches/theta/SetOperation.java | 5 +++--
.../org/apache/datasketches/theta/AnotBimplTest.java | 6 ++++++
.../apache/datasketches/theta/CompactSketchTest.java | 11 +++++++++++
.../java/org/apache/datasketches/theta/EmptyTest.java | 15 +++++++++++++--
.../datasketches/theta/HeapIntersectionTest.java | 2 +-
.../datasketches/theta/SingleItemSketchTest.java | 15 +++++++++++++++
.../java/org/apache/datasketches/theta/SketchTest.java | 11 +++++++++++
9 files changed, 70 insertions(+), 19 deletions(-)
diff --git a/src/main/java/org/apache/datasketches/theta/IntersectionImpl.java b/src/main/java/org/apache/datasketches/theta/IntersectionImpl.java
index 611130d..7dd1368 100644
--- a/src/main/java/org/apache/datasketches/theta/IntersectionImpl.java
+++ b/src/main/java/org/apache/datasketches/theta/IntersectionImpl.java
@@ -55,10 +55,6 @@ final class IntersectionImpl extends IntersectionImplR {
super(wmem, seed, newMem);
}
- IntersectionImpl(final short seedHash) {
- super(seedHash);
- }
-
/**
* Construct a new Intersection target on the java heap.
*
@@ -260,7 +256,7 @@ final class IntersectionImpl extends IntersectionImplR {
performIntersect(sketchIn);
break;
}
- default: assert false : "Should not happen";
+ //default: assert false : "Should not happen";
}
}
diff --git a/src/main/java/org/apache/datasketches/theta/IntersectionImplR.java b/src/main/java/org/apache/datasketches/theta/IntersectionImplR.java
index 65359d2..e63d708 100644
--- a/src/main/java/org/apache/datasketches/theta/IntersectionImplR.java
+++ b/src/main/java/org/apache/datasketches/theta/IntersectionImplR.java
@@ -83,15 +83,15 @@ class IntersectionImplR extends Intersection {
}
}
- IntersectionImplR(final short seedHash) {
- seedHash_ = seedHash;
- mem_ = null;
- lgArrLongs_ = 0;
- curCount_ = -1;
- thetaLong_ = Long.MAX_VALUE;
- empty_ = false;
- hashTable_ = null;
- }
+ // IntersectionImplR(final short seedHash) {
+ // seedHash_ = seedHash;
+ // mem_ = null;
+ // lgArrLongs_ = 0;
+ // curCount_ = -1;
+ // thetaLong_ = Long.MAX_VALUE;
+ // empty_ = false;
+ // hashTable_ = null;
+ // }
/**
* Wrap an Intersection target around the given source Memory containing intersection data.
diff --git a/src/main/java/org/apache/datasketches/theta/SetOperation.java b/src/main/java/org/apache/datasketches/theta/SetOperation.java
index a38b719..b43977c 100644
--- a/src/main/java/org/apache/datasketches/theta/SetOperation.java
+++ b/src/main/java/org/apache/datasketches/theta/SetOperation.java
@@ -204,11 +204,12 @@ public abstract class SetOperation {
/**
* Returns the maximum number of bytes for the returned CompactSketch, given the maximum
* value of nomEntries of the first sketch A of AnotB.
- * @param maxNomEntries the given value
+ * @param maxNomEntries the given value must be a power of 2.
* @return the maximum number of bytes.
*/
public static int getMaxAnotBResultBytes(final int maxNomEntries) {
- return 24 + (15 * maxNomEntries);
+ final int ceil = ceilingPowerOf2(maxNomEntries);
+ return 24 + (15 * ceil);
}
diff --git a/src/test/java/org/apache/datasketches/theta/AnotBimplTest.java b/src/test/java/org/apache/datasketches/theta/AnotBimplTest.java
index 3ad0559..6d20235 100644
--- a/src/test/java/org/apache/datasketches/theta/AnotBimplTest.java
+++ b/src/test/java/org/apache/datasketches/theta/AnotBimplTest.java
@@ -378,6 +378,12 @@ public class AnotBimplTest {
}
@Test
+ public void checkGetMaxBytes() {
+ int bytes = Sketches.getMaxAnotBResultBytes(10);
+ assertEquals(bytes, (16 * 15) + 24);
+ }
+
+ @Test
public void printlnTest() {
println("PRINTING: "+this.getClass().getName());
}
diff --git a/src/test/java/org/apache/datasketches/theta/CompactSketchTest.java b/src/test/java/org/apache/datasketches/theta/CompactSketchTest.java
index fe8347e..f8f1811 100644
--- a/src/test/java/org/apache/datasketches/theta/CompactSketchTest.java
+++ b/src/test/java/org/apache/datasketches/theta/CompactSketchTest.java
@@ -323,6 +323,17 @@ public class CompactSketchTest {
assertTrue(cache.length == 0);
}
+ @Test
+ public void checkHeapCompactSketchCompact() {
+ UpdateSketch sk = Sketches.updateSketchBuilder().build();
+ sk.update(1);
+ sk.update(2);
+ CompactSketch csk = sk.compact();
+ CompactSketch csk2 = csk.compact();
+ assertTrue(csk.isOrdered());
+ assertEquals(csk.getCurrentPreambleLongs(), 2);
+ }
+
private static class State {
String classType = null;
int count = 0;
diff --git a/src/test/java/org/apache/datasketches/theta/EmptyTest.java b/src/test/java/org/apache/datasketches/theta/EmptyTest.java
index 7b93117..480421e 100644
--- a/src/test/java/org/apache/datasketches/theta/EmptyTest.java
+++ b/src/test/java/org/apache/datasketches/theta/EmptyTest.java
@@ -136,6 +136,19 @@ public class EmptyTest {
Sketches.heapifySketch(mem);
}
+ @Test
+ public void checkEmptyToCompact() {
+ UpdateSketch sk1 = Sketches.updateSketchBuilder().build();
+ CompactSketch csk = sk1.compact();
+ assertTrue(csk instanceof EmptyCompactSketch);
+ CompactSketch csk2 = csk.compact();
+ assertTrue(csk2 instanceof EmptyCompactSketch);
+ CompactSketch csk3 = csk.compact(true, WritableMemory.allocate(8));
+ assertTrue(csk3 instanceof DirectCompactSketch);
+ assertEquals(csk2.getCurrentPreambleLongs(), 1);
+ }
+
+
//SerVer 2 had an empty sketch where preLongs = 1, but empty bit was not set.
private static Memory badEmptySk() {
final long preLongs = 1;
@@ -150,8 +163,6 @@ public class EmptyTest {
return wmem;
}
-
-
/**
* @param s value to print
*/
diff --git a/src/test/java/org/apache/datasketches/theta/HeapIntersectionTest.java b/src/test/java/org/apache/datasketches/theta/HeapIntersectionTest.java
index 4008203..f4abbca 100644
--- a/src/test/java/org/apache/datasketches/theta/HeapIntersectionTest.java
+++ b/src/test/java/org/apache/datasketches/theta/HeapIntersectionTest.java
@@ -509,7 +509,7 @@ public class HeapIntersectionTest {
byte[] byteArray = union.toByteArray();
Memory mem = Memory.wrap(byteArray);
Intersection inter1 = (Intersection) SetOperation.heapify(mem); //bad cast
- println(inter1.toString());
+ //println(inter1.toString());
}
@Test(expectedExceptions = SketchesArgumentException.class)
diff --git a/src/test/java/org/apache/datasketches/theta/SingleItemSketchTest.java b/src/test/java/org/apache/datasketches/theta/SingleItemSketchTest.java
index 01226bf..dbb8088 100644
--- a/src/test/java/org/apache/datasketches/theta/SingleItemSketchTest.java
+++ b/src/test/java/org/apache/datasketches/theta/SingleItemSketchTest.java
@@ -323,6 +323,21 @@ public class SingleItemSketchTest {
//println(sk.toString());
}
+ @Test
+ public void checkSingleItemCompact() {
+ UpdateSketch sk1 = new UpdateSketchBuilder().build();
+ sk1.update(1);
+ CompactSketch csk = sk1.compact();
+ assertTrue(csk instanceof SingleItemSketch);
+ CompactSketch csk2 = csk.compact();
+ assertEquals(csk, csk2);
+ CompactSketch csk3 = csk.compact(true, WritableMemory.allocate(16));
+ assertTrue(csk3 instanceof DirectCompactSketch);
+ assertEquals(csk2.getCurrentPreambleLongs(), 1);
+ assertEquals(csk3.getCurrentPreambleLongs(), 1);
+ }
+
+
static final long SiSkPre0WithSiFlag = 0x93cc3a0000030301L;
static final long SiSkPre0WoutSiFlag = 0x93cc1a0000030301L;
static final long Hash = 0x05a186bdcb7df915L;
diff --git a/src/test/java/org/apache/datasketches/theta/SketchTest.java b/src/test/java/org/apache/datasketches/theta/SketchTest.java
index 1193e38..18c7ed7 100644
--- a/src/test/java/org/apache/datasketches/theta/SketchTest.java
+++ b/src/test/java/org/apache/datasketches/theta/SketchTest.java
@@ -409,7 +409,18 @@ public class SketchTest {
sk = Sketch.heapify(wmem);
fail();
} catch (SketchesArgumentException e) { }
+ }
+ @Test
+ public void check2Methods() {
+ int k = 16;
+ Sketch sk = Sketches.updateSketchBuilder().setNominalEntries(k).build();
+ int bytes1 = sk.getCurrentBytes(true);
+ int bytes2 = sk.getCurrentBytes(false);
+ assertEquals(bytes1, 8);
+ assertEquals(bytes2, 280); //32*8 + 24
+ int retEnt = sk.getRetainedEntries();
+ assertEquals(retEnt, 0);
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org