Skip to content

Commit cfff061

Browse files
committed
Fix BinomialBoundsN may divide 0
1 parent ca1fef0 commit cfff061

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/main/java/org/apache/datasketches/thetacommon/BinomialBoundsN.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static void checkArgs(final long numSamples, final double theta, final int numSD
272272
"numSDev must only be 1,2, or 3 and numSamples must >= 0: numSDev="
273273
+ numSDev + ", numSamples=" + numSamples);
274274
}
275-
if ((theta < 0.0) || (theta > 1.0)) {
275+
if ((theta <= 0.0) || (theta > 1.0)) {
276276
throw new SketchesArgumentException("0.0 < theta <= 1.0: " + theta);
277277
}
278278
}

src/test/java/org/apache/datasketches/thetacommon/BinomialBoundsNTest.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
import static org.apache.datasketches.thetacommon.BinomialBoundsN.checkArgs;
2323
import static org.apache.datasketches.thetacommon.BinomialBoundsN.getLowerBound;
2424
import static org.apache.datasketches.thetacommon.BinomialBoundsN.getUpperBound;
25-
import static org.testng.Assert.assertEquals;
26-
import static org.testng.Assert.assertTrue;
27-
import static org.testng.Assert.fail;
25+
import static org.testng.Assert.*;
2826

2927
import org.apache.datasketches.common.SketchesArgumentException;
3028
import org.apache.datasketches.thetacommon.BinomialBoundsN;
@@ -119,17 +117,17 @@ public static void checkBounds() {
119117

120118
@Test
121119
public static void checkCheckArgs() {
122-
try {
123-
checkArgs(-1L, 1.0, 1);
124-
checkArgs(10L, 0.0, 1);
125-
checkArgs(10L, 1.01, 1);
126-
checkArgs(10L, 1.0, 3);
127-
checkArgs(10L, 1.0, 0);
128-
checkArgs(10L, 1.0, 4);
129-
fail("Expected SketchesArgumentException");
130-
} catch (final SketchesArgumentException e) {
131-
//pass
132-
}
120+
assertThrows(SketchesArgumentException.class,
121+
() -> checkArgs(-1L, 1.0, 1));
122+
assertThrows(SketchesArgumentException.class,
123+
() -> checkArgs(10L, 0.0, 1));
124+
assertThrows(SketchesArgumentException.class,
125+
() -> checkArgs(10L, 1.01, 1));
126+
checkArgs(10L, 1.0, 3);
127+
assertThrows(SketchesArgumentException.class,
128+
() -> checkArgs(10L, 1.0, 0));
129+
assertThrows(SketchesArgumentException.class,
130+
() -> checkArgs(10L, 1.0, 4));
133131
}
134132

135133
@Test

0 commit comments

Comments
 (0)