Skip to content

Commit

Permalink
Number test Cases 2
Browse files Browse the repository at this point in the history
  • Loading branch information
sathishk committed Mar 1, 2024
1 parent 659f944 commit 37ee894
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/techatpark/sjson/core/NumberParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private static Number getLongOrBigNumber(final String source,
BigInteger bigInteger = new BigInteger(source);
if (isNegative) {
bigInteger = bigInteger.multiply(new BigInteger("-1"));
if (bigInteger.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < -1) {
if (bigInteger.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) > -1) {
return bigInteger.longValue();
}
return bigInteger;
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/com/techatpark/sjson/core/NumberParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.IOException;
import java.io.StringReader;
import java.math.BigInteger;
import java.nio.file.Path;
import java.util.List;
import java.util.Set;
Expand All @@ -34,8 +35,7 @@ class NumberParserTest {
@ParameterizedTest
@MethodSource("numbers")
void testValid(final Number originalValue) throws IOException {
String jsonString = objectMapper.writeValueAsString(originalValue);
Assertions.assertEquals(originalValue, new Json().read(new StringReader(jsonString)));
Assertions.assertEquals(originalValue, new Json().read(new StringReader(originalValue.toString())));
}

/**
Expand All @@ -52,6 +52,10 @@ private static List<Number> numbers() {
Short.MAX_VALUE,
Integer.MIN_VALUE,
Integer.MAX_VALUE,
Long.MIN_VALUE,
Long.MAX_VALUE,
BigInteger.valueOf(Long.MIN_VALUE).multiply(BigInteger.TEN),
BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.TEN),
Float.MIN_VALUE,
Float.MAX_VALUE,
Double.MIN_VALUE
Expand Down

0 comments on commit 37ee894

Please sign in to comment.