You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2019/08/08 17:30:32 UTC
[commons-numbers] 09/18: NUMBERS-120: Add unit tests
This is an automated email from the ASF dual-hosted git repository.
erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git
commit f6a2e09df40f8d93f808e6072e48c2c144b70b8c
Author: Schamschi <he...@gmx.at>
AuthorDate: Thu Jun 27 23:45:23 2019 +0200
NUMBERS-120: Add unit tests
---
.../commons/numbers/fraction/BigFractionTest.java | 61 +++++++++++++++++++---
1 file changed, 55 insertions(+), 6 deletions(-)
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
index 950e7cc..cb6061d 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
@@ -171,6 +171,8 @@ public class BigFractionTest {
@Test
public void testDoubleValue() {
+ Assertions.assertEquals(0d, BigFraction.ZERO.doubleValue(), 0d);
+
{
BigFraction first = BigFraction.of(1, 2);
BigFraction second = BigFraction.of(1, 3);
@@ -180,16 +182,37 @@ public class BigFractionTest {
}
//NUMBERS-120
- {
- BigFraction f = BigFraction.of(
- BigInteger.ONE.shiftLeft(54),
- BigInteger.ONE.shiftLeft(53).add(BigInteger.ONE));
- Assertions.assertEquals(2d - 0x1P-52, f.doubleValue());
- }
+ Assertions.assertEquals(
+ 2d - 0x1P-52,
+ BigFraction.of(
+ BigInteger.ONE.shiftLeft(54),
+ BigInteger.ONE.shiftLeft(53).add(BigInteger.ONE)
+ ).doubleValue());
+
+ Assertions.assertEquals(
+ 2d,
+ BigFraction.of(
+ BigInteger.ONE.shiftLeft(54).subtract(BigInteger.ONE),
+ BigInteger.ONE.shiftLeft(53)
+ ).doubleValue());
+ Assertions.assertEquals(
+ 1d,
+ BigFraction.of(
+ BigInteger.ONE.shiftLeft(53).add(BigInteger.ONE),
+ BigInteger.ONE.shiftLeft(53)
+ ).doubleValue());
}
@Test
public void testDoubleValueForSubnormalNumbers() {
+ //test Double.MIN_VALUE * 2/3
+ Assertions.assertEquals(
+ Double.MIN_VALUE,
+ BigFraction.of(
+ BigInteger.ONE,
+ BigInteger.ONE.shiftLeft(1073).multiply(BigInteger.valueOf(3L))
+ ).doubleValue());
+
Assertions.assertEquals(
Double.MIN_VALUE,
BigFraction.of(
@@ -223,6 +246,23 @@ public class BigFractionTest {
).doubleValue());
}
+ @Test
+ public void testDoubleValueForInfinities() {
+ Assertions.assertEquals(
+ Double.NEGATIVE_INFINITY,
+ BigFraction.of(
+ BigInteger.ONE.shiftLeft(1024)
+ .subtract(BigInteger.ONE.shiftLeft(970))
+ .negate()
+ ).doubleValue());
+ Assertions.assertEquals(
+ Double.POSITIVE_INFINITY,
+ BigFraction.of(
+ BigInteger.ONE.shiftLeft(1024)
+ .subtract(BigInteger.ONE.shiftLeft(970))
+ ).doubleValue());
+ }
+
// MATH-744
@Test
public void testDoubleValueForLargeNumeratorAndDenominator() {
@@ -268,6 +308,15 @@ public class BigFractionTest {
BigInteger.valueOf(3));
Assertions.assertEquals(5.992310449541053E307, f.doubleValue());
}
+
+ {
+ BigFraction f = BigFraction.of(
+ BigInteger.ONE.shiftLeft(1025)
+ .subtract(BigInteger.ONE.shiftLeft(972))
+ .subtract(BigInteger.ONE),
+ BigInteger.valueOf(2));
+ Assertions.assertEquals(Double.MAX_VALUE, f.doubleValue());
+ }
}
// NUMBERS-15