Search in sources :

Example 6 with SketchesStateException

use of org.apache.datasketches.SketchesStateException in project sketches-core by DataSketches.

the class AdoubleIntersectionTest method checkExactIntersectionWithTheta.

@Test
public void checkExactIntersectionWithTheta() {
    final UpdateSketch thSkNull = null;
    final UpdateSketch thSkEmpty = new UpdateSketchBuilder().build();
    final UpdateSketch thSk10 = new UpdateSketchBuilder().build();
    final UpdateSketch thSk15 = new UpdateSketchBuilder().build();
    for (int i = 0; i < 10; i++) {
        thSk10.update(i);
    }
    // overlap = 5
    for (int i = 0; i < 10; i++) {
        thSk15.update(i + 5);
    }
    DoubleSummary dsum = new DoubleSummaryFactory(mode).newSummary();
    final Intersection<DoubleSummary> intersection = new Intersection<>(new DoubleSummarySetOperations(mode, mode));
    CompactSketch<DoubleSummary> result;
    try {
        intersection.getResult();
        fail();
    }// OK.
     catch (final SketchesStateException e) {
    }
    try {
        intersection.intersect(thSkNull, dsum);
        fail();
    }// OK
     catch (final SketchesArgumentException e) {
    }
    intersection.intersect(thSkEmpty, dsum);
    result = intersection.getResult();
    // Empty after empty first call
    Assert.assertTrue(result.isEmpty());
    intersection.reset();
    intersection.intersect(thSk10, dsum);
    result = intersection.getResult();
    // Returns valid first call
    Assert.assertEquals(result.getEstimate(), 10.0);
    intersection.reset();
    // Valid first call
    intersection.intersect(thSk10, dsum);
    intersection.intersect(thSkEmpty, dsum);
    result = intersection.getResult();
    // Returns Empty after empty second call
    Assert.assertTrue(result.isEmpty());
    intersection.reset();
    intersection.intersect(thSk10, dsum);
    intersection.intersect(thSk15, dsum);
    result = intersection.getResult();
    // Returns intersection
    Assert.assertEquals(result.getEstimate(), 5.0);
    intersection.reset();
    dsum = null;
    try {
        intersection.intersect(thSk10, dsum);
        fail();
    } catch (final SketchesArgumentException e) {
    }
}
Also used : Intersection(org.apache.datasketches.tuple.Intersection) SketchesArgumentException(org.apache.datasketches.SketchesArgumentException) UpdateSketchBuilder(org.apache.datasketches.theta.UpdateSketchBuilder) SketchesStateException(org.apache.datasketches.SketchesStateException) UpdateSketch(org.apache.datasketches.theta.UpdateSketch) Test(org.testng.annotations.Test)

Aggregations

SketchesStateException (org.apache.datasketches.SketchesStateException)6 WritableMemory (org.apache.datasketches.memory.WritableMemory)4 Test (org.testng.annotations.Test)4 SketchesArgumentException (org.apache.datasketches.SketchesArgumentException)3 Memory (org.apache.datasketches.memory.Memory)1 UpdateSketch (org.apache.datasketches.theta.UpdateSketch)1 UpdateSketchBuilder (org.apache.datasketches.theta.UpdateSketchBuilder)1 Intersection (org.apache.datasketches.tuple.Intersection)1