Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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 @@ -644,7 +644,9 @@ char next() {
return pos == str.length() ? '\0' : str.charAt(pos++);
}

// maximum of 6 digits
int nextUInt() {
int mark = pos;
char c = next();
if (!isDigit(c)) {
if (c != '\0')
Expand All @@ -654,10 +656,9 @@ int nextUInt() {
int res = c - '0';
while (isDigit(c = next())) {
res = (10 * res) + (c - '0');
if (res <= 0) {
throw new NumberFormatException("Integer too large, overflowed");
}
}
if (pos - mark > 7)
throw new NumberFormatException("Value too large, 7 digits max!");
if (c != '\0')
pos--;
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1346,15 +1346,14 @@ public void testImplicitH() throws Exception {
@Test
public void largeNumberOfAtoms() {
IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
assertThat(getAtomCount(getMolecularFormula("C2147483647", builder)),
is(2147483647));
assertThat(getAtomCount(getMolecularFormula("C9999999", builder)),
is(9999999));
}

@Test(expected = NumberFormatException.class)
public void tooLargeNumberOfAtoms() {
IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
assertThat(getAtomCount(getMolecularFormula("C2147483648", builder)),
is(2147483647));
getAtomCount(getMolecularFormula("C10000000", builder)); // should throw
}

@Test
Expand Down