Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,8 @@ void update(final T item, final double weight, final boolean mark) {
if (item == null) {
return;
}
if (weight <= 0.0) {
throw new SketchesArgumentException("Item weights must be strictly positive: "
if (weight <= 0.0 || Double.isNaN(weight) || Double.isInfinite(weight)) {
throw new SketchesArgumentException("Item weights must be strictly positive and finite number: "
+ weight + ", for item " + item.toString());
}
++n_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,18 @@ public void checkInvalidWeight() {
vis.update("invalidWeight", -1.0); // should fail
}

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkNaNWeight() {
final VarOptItemsSketch<String> vis = VarOptItemsSketch.newInstance(5);
vis.update("invalidWeight", Double.NaN);
}

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkInfiniteWeight() {
final VarOptItemsSketch<String> vis = VarOptItemsSketch.newInstance(5);
vis.update("invalidWeight", Double.POSITIVE_INFINITY);
}

@Test
public void checkCorruptSerializedWeight() {
final VarOptItemsSketch<String> vis = VarOptItemsSketch.newInstance(24);
Expand Down
Loading