Skip to content

Commit 07c5ae9

Browse files
authored
Merge pull request #708 from ZENOTME/fix_binomial_bounds
Fix BinomialBoundsN may divide 0
2 parents ad0639c + ad3f061 commit 07c5ae9

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static org.testng.Assert.assertEquals;
2626
import static org.testng.Assert.assertTrue;
2727
import static org.testng.Assert.fail;
28+
import static org.testng.Assert.assertThrows;
2829

2930
import org.apache.datasketches.common.SketchesArgumentException;
3031
import org.apache.datasketches.thetacommon.BinomialBoundsN;
@@ -119,17 +120,17 @@ public static void checkBounds() {
119120

120121
@Test
121122
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-
}
123+
assertThrows(SketchesArgumentException.class,
124+
() -> checkArgs(-1L, 1.0, 1));
125+
assertThrows(SketchesArgumentException.class,
126+
() -> checkArgs(10L, 0.0, 1));
127+
assertThrows(SketchesArgumentException.class,
128+
() -> checkArgs(10L, 1.01, 1));
129+
checkArgs(10L, 1.0, 3);
130+
assertThrows(SketchesArgumentException.class,
131+
() -> checkArgs(10L, 1.0, 0));
132+
assertThrows(SketchesArgumentException.class,
133+
() -> checkArgs(10L, 1.0, 4));
133134
}
134135

135136
@Test

0 commit comments

Comments
 (0)