public void testRoundInfiniteToBigIntegerAlwaysFails() { for (RoundingMode mode : ALL_ROUNDING_MODES) { try { DoubleMath.roundToBigInteger(Double.POSITIVE_INFINITY, mode); fail("Expected ArithmeticException"); } catch (ArithmeticException expected) { } try { DoubleMath.roundToBigInteger(Double.NEGATIVE_INFINITY, mode); fail("Expected ArithmeticException"); } catch (ArithmeticException expected) { } } }
public void testRoundFractionalDoubleToBigInteger() { for (double d : FRACTIONAL_DOUBLE_CANDIDATES) { for (RoundingMode mode : ALL_SAFE_ROUNDING_MODES) { BigDecimal expected = new BigDecimal(d).setScale(0, mode); assertEquals(expected.toBigInteger(), DoubleMath.roundToBigInteger(d, mode)); } } }
public void testRoundNaNToBigIntegerAlwaysFails() { for (RoundingMode mode : ALL_ROUNDING_MODES) { try { DoubleMath.roundToBigInteger(Double.NaN, mode); fail("Expected ArithmeticException"); } catch (ArithmeticException expected) { } } }
public void testRoundExactFractionalDoubleToBigIntegerFails() { for (double d : FRACTIONAL_DOUBLE_CANDIDATES) { try { DoubleMath.roundToBigInteger(d, UNNECESSARY); fail("Expected ArithmeticException"); } catch (ArithmeticException expected) { } } }
public void testRoundExactIntegralDoubleToBigInteger() { for (double d : INTEGRAL_DOUBLE_CANDIDATES) { BigDecimal expected = new BigDecimal(d).setScale(0, UNNECESSARY); assertEquals(expected.toBigInteger(), DoubleMath.roundToBigInteger(d, UNNECESSARY)); } }