Skip to content
Permalink
Browse files
test all constructors
  • Loading branch information
AlexanderSaydakov committed Jul 11, 2017
1 parent 3e18d39 commit ef9f1242e4d2d4a79485b3d088a18f393bff5fa1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
@@ -16,6 +16,7 @@
import org.testng.annotations.Test;

import com.yahoo.sketches.hll.HllSketch;
import com.yahoo.sketches.hll.TgtHllType;

public class DataToSketchTest {

@@ -32,18 +33,21 @@ public void execNullInputTuple() throws Exception {

@Test
public void execEmptyInputTuple() throws Exception {
EvalFunc<DataByteArray> func = new DataToSketch();
EvalFunc<DataByteArray> func = new DataToSketch("10");
DataByteArray result = func.exec(tupleFactory.newTuple());
HllSketch sketch = getSketch(result);
Assert.assertTrue(sketch.isEmpty());
Assert.assertEquals(sketch.getLgConfigK(), 10);
}

@Test
public void execEmptyBag() throws Exception {
EvalFunc<DataByteArray> func = new DataToSketch();
EvalFunc<DataByteArray> func = new DataToSketch("10", "HLL_6");
DataByteArray result = func.exec(tupleFactory.newTuple(bagFactory.newDefaultBag()));
HllSketch sketch = getSketch(result);
Assert.assertTrue(sketch.isEmpty());
Assert.assertEquals(sketch.getLgConfigK(), 10);
Assert.assertEquals(sketch.getTgtHllType(), TgtHllType.HLL_6);
}

@Test(expectedExceptions = IllegalArgumentException.class)
@@ -139,16 +143,19 @@ public void algebraicIntermediateNullInputTuple() throws Exception {
@Test
public void algebraicIntermediateEmptyInputTuple() throws Exception {
EvalFunc<Tuple> func =
(EvalFunc<Tuple>) Class.forName(new DataToSketch().getIntermed()).newInstance();
(EvalFunc<Tuple>) Class.forName(new DataToSketch().getIntermed())
.getConstructor(String.class).newInstance("10");
Tuple result = func.exec(tupleFactory.newTuple());
HllSketch sketch = getSketch((DataByteArray) result.get(0));
Assert.assertTrue(sketch.isEmpty());
Assert.assertEquals(sketch.getLgConfigK(), 10);
}

@Test
public void algebraicIntermediateFromInitial() throws Exception {
EvalFunc<Tuple> func =
(EvalFunc<Tuple>) Class.forName(new DataToSketch().getIntermed()).newInstance();
(EvalFunc<Tuple>) Class.forName(new DataToSketch().getIntermed())
.getConstructor(String.class, String.class).newInstance("10", "HLL_6");
DataBag outerBag = bagFactory.newDefaultBag();
DataBag innerBag = bagFactory.newDefaultBag();
innerBag.add(tupleFactory.newTuple("a"));
@@ -159,6 +166,8 @@ public void algebraicIntermediateFromInitial() throws Exception {
HllSketch sketch = getSketch((DataByteArray) result.get(0));
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getEstimate(), 3.0, 0.01);
Assert.assertEquals(sketch.getLgConfigK(), 10);
Assert.assertEquals(sketch.getTgtHllType(), TgtHllType.HLL_6);
}

@Test
@@ -188,16 +197,19 @@ public void algebraicFinalNullInputTuple() throws Exception {
@Test
public void algebraicFinalEmptyInputTuple() throws Exception {
EvalFunc<DataByteArray> func =
(EvalFunc<DataByteArray>) Class.forName(new DataToSketch().getFinal()).newInstance();
(EvalFunc<DataByteArray>) Class.forName(new DataToSketch().getFinal())
.getConstructor(String.class).newInstance("10");
DataByteArray result = func.exec(tupleFactory.newTuple());
HllSketch sketch = getSketch(result);
Assert.assertTrue(sketch.isEmpty());
Assert.assertEquals(sketch.getLgConfigK(), 10);
}

@Test
public void algebraicFinalFromInitial() throws Exception {
EvalFunc<DataByteArray> func =
(EvalFunc<DataByteArray>) Class.forName(new DataToSketch().getFinal()).newInstance();
(EvalFunc<DataByteArray>) Class.forName(new DataToSketch().getFinal())
.getConstructor(String.class, String.class).newInstance("10", "HLL_6");
DataBag outerBag = bagFactory.newDefaultBag();
DataBag innerBag = bagFactory.newDefaultBag();
innerBag.add(tupleFactory.newTuple("a"));
@@ -208,6 +220,8 @@ public void algebraicFinalFromInitial() throws Exception {
HllSketch sketch = getSketch(result);
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getEstimate(), 3.0, 0.01);
Assert.assertEquals(sketch.getLgConfigK(), 10);
Assert.assertEquals(sketch.getTgtHllType(), TgtHllType.HLL_6);
}

@Test
@@ -16,6 +16,7 @@
import org.testng.annotations.Test;

import com.yahoo.sketches.hll.HllSketch;
import com.yahoo.sketches.hll.TgtHllType;

public class UnionSketchTest {

@@ -32,18 +33,21 @@ public void execNullInputTuple() throws Exception {

@Test
public void execEmptyInputTuple() throws Exception {
EvalFunc<DataByteArray> func = new UnionSketch();
EvalFunc<DataByteArray> func = new UnionSketch("10");
DataByteArray result = func.exec(tupleFactory.newTuple());
HllSketch sketch = DataToSketchTest.getSketch(result);
Assert.assertTrue(sketch.isEmpty());
Assert.assertEquals(sketch.getLgConfigK(), 10);
}

@Test
public void execEmptyBag() throws Exception {
EvalFunc<DataByteArray> func = new UnionSketch();
EvalFunc<DataByteArray> func = new UnionSketch("10", "HLL_6");
DataByteArray result = func.exec(tupleFactory.newTuple(bagFactory.newDefaultBag()));
HllSketch sketch = DataToSketchTest.getSketch(result);
Assert.assertTrue(sketch.isEmpty());
Assert.assertEquals(sketch.getLgConfigK(), 10);
Assert.assertEquals(sketch.getTgtHllType(), TgtHllType.HLL_6);
}

@Test
@@ -127,16 +131,19 @@ public void algebraicIntermediateNullInputTuple() throws Exception {
@Test
public void algebraicIntermediateEmptyInputTuple() throws Exception {
EvalFunc<Tuple> func =
(EvalFunc<Tuple>) Class.forName(new UnionSketch().getIntermed()).newInstance();
(EvalFunc<Tuple>) Class.forName(new UnionSketch().getIntermed())
.getConstructor(String.class).newInstance("10");
Tuple result = func.exec(tupleFactory.newTuple());
HllSketch sketch = DataToSketchTest.getSketch((DataByteArray) result.get(0));
Assert.assertTrue(sketch.isEmpty());
Assert.assertEquals(sketch.getLgConfigK(), 10);
}

@Test
public void algebraicIntermediateFromInitial() throws Exception {
EvalFunc<Tuple> func =
(EvalFunc<Tuple>) Class.forName(new UnionSketch().getIntermed()).newInstance();
(EvalFunc<Tuple>) Class.forName(new UnionSketch().getIntermed())
.getConstructor(String.class, String.class).newInstance("10", "HLL_6");
HllSketch inputSketch = new HllSketch(12);
inputSketch.update(1);
inputSketch.update(2);
@@ -149,6 +156,8 @@ public void algebraicIntermediateFromInitial() throws Exception {
HllSketch sketch = DataToSketchTest.getSketch((DataByteArray) result.get(0));
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getEstimate(), 3.0, 0.01);
Assert.assertEquals(sketch.getLgConfigK(), 10);
Assert.assertEquals(sketch.getTgtHllType(), TgtHllType.HLL_6);
}

@Test
@@ -178,16 +187,19 @@ public void algebraicFinalNullInputTuple() throws Exception {
@Test
public void algebraicFinalEmptyInputTuple() throws Exception {
EvalFunc<DataByteArray> func =
(EvalFunc<DataByteArray>) Class.forName(new UnionSketch().getFinal()).newInstance();
(EvalFunc<DataByteArray>) Class.forName(new UnionSketch().getFinal())
.getConstructor(String.class).newInstance("10");
DataByteArray result = func.exec(tupleFactory.newTuple());
HllSketch sketch = DataToSketchTest.getSketch(result);
Assert.assertTrue(sketch.isEmpty());
Assert.assertEquals(sketch.getLgConfigK(), 10);
}

@Test
public void algebraicFinalFromInitial() throws Exception {
EvalFunc<DataByteArray> func =
(EvalFunc<DataByteArray>) Class.forName(new UnionSketch().getFinal()).newInstance();
(EvalFunc<DataByteArray>) Class.forName(new UnionSketch().getFinal())
.getConstructor(String.class, String.class).newInstance("10", "HLL_6");
HllSketch inputSketch = new HllSketch(12);
inputSketch.update(1);
inputSketch.update(2);
@@ -200,6 +212,8 @@ public void algebraicFinalFromInitial() throws Exception {
HllSketch sketch = DataToSketchTest.getSketch(result);
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getEstimate(), 3.0, 0.01);
Assert.assertEquals(sketch.getLgConfigK(), 10);
Assert.assertEquals(sketch.getTgtHllType(), TgtHllType.HLL_6);
}

@Test

0 comments on commit ef9f124

Please sign in to comment.