Search in sources :

Example 1 with SketchesException

use of com.yahoo.sketches.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(com.yahoo.sketches.ResizeFactor) SketchesException(com.yahoo.sketches.SketchesException) Test(org.testng.annotations.Test)

Example 2 with SketchesException

use of com.yahoo.sketches.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(com.yahoo.sketches.ResizeFactor) SketchesException(com.yahoo.sketches.SketchesException) Test(org.testng.annotations.Test)

Aggregations

ResizeFactor (com.yahoo.sketches.ResizeFactor)2 SketchesException (com.yahoo.sketches.SketchesException)2 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1