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"));
}
}
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"));
}
}
Aggregations