Search in sources :

Example 1 with SketchesException

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

the class ReservoirLongsSketchTest method checkBadConstructorArgs.

@Test
public void checkBadConstructorArgs() {
    final long[] data = new long[128];
    for (int i = 0; i < 128; ++i) {
        data[i] = i;
    }
    final ResizeFactor rf = ResizeFactor.X8;
    // no items
    try {
        ReservoirLongsSketch.getInstance(null, 128, rf, 128);
        fail();
    } catch (final SketchesException e) {
        assertTrue(e.getMessage().contains("null reservoir"));
    }
    // size too small
    try {
        ReservoirLongsSketch.getInstance(data, 128, rf, 1);
        fail();
    } catch (final SketchesException e) {
        assertTrue(e.getMessage().contains("size less than 2"));
    }
    // configured reservoir size smaller than items length
    try {
        ReservoirLongsSketch.getInstance(data, 128, rf, 64);
        fail();
    } catch (final SketchesException e) {
        assertTrue(e.getMessage().contains("max size less than array length"));
    }
    // too many items seen vs items length, full sketch
    try {
        ReservoirLongsSketch.getInstance(data, 512, rf, 256);
        fail();
    } catch (final SketchesException e) {
        assertTrue(e.getMessage().contains("too few samples"));
    }
    // too many items seen vs items length, under-full sketch
    try {
        ReservoirLongsSketch.getInstance(data, 256, rf, 256);
        fail();
    } catch (final SketchesException e) {
        assertTrue(e.getMessage().contains("too few samples"));
    }
}
Also used : ResizeFactor(org.apache.datasketches.ResizeFactor) SketchesException(org.apache.datasketches.SketchesException) Test(org.testng.annotations.Test)

Example 2 with SketchesException

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

the class ReservoirItemsSketchTest method checkBadConstructorArgs.

@Test
public void checkBadConstructorArgs() {
    final ArrayList<String> data = new ArrayList<>(128);
    for (int i = 0; i < 128; ++i) {
        data.add(Integer.toString(i));
    }
    final ResizeFactor rf = ResizeFactor.X8;
    // no items
    try {
        ReservoirItemsSketch.<Byte>newInstance(null, 128, rf, 128);
        fail();
    } catch (final SketchesException e) {
        assertTrue(e.getMessage().contains("null reservoir"));
    }
    // size too small
    try {
        ReservoirItemsSketch.newInstance(data, 128, rf, 1);
        fail();
    } catch (final SketchesException e) {
        assertTrue(e.getMessage().contains("size less than 2"));
    }
    // configured reservoir size smaller than items length
    try {
        ReservoirItemsSketch.newInstance(data, 128, rf, 64);
        fail();
    } catch (final SketchesException e) {
        assertTrue(e.getMessage().contains("max size less than array length"));
    }
    // too many items seen vs items length, full sketch
    try {
        ReservoirItemsSketch.newInstance(data, 512, rf, 256);
        fail();
    } catch (final SketchesException e) {
        assertTrue(e.getMessage().contains("too few samples"));
    }
    // too many items seen vs items length, under-full sketch
    try {
        ReservoirItemsSketch.newInstance(data, 256, rf, 256);
        fail();
    } catch (final SketchesException e) {
        assertTrue(e.getMessage().contains("too few samples"));
    }
}
Also used : ArrayList(java.util.ArrayList) ResizeFactor(org.apache.datasketches.ResizeFactor) SketchesException(org.apache.datasketches.SketchesException) Test(org.testng.annotations.Test)

Aggregations

ResizeFactor (org.apache.datasketches.ResizeFactor)2 SketchesException (org.apache.datasketches.SketchesException)2 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1