public void modifyDecimal(IonDecimal value) { float fVal = 123.45F; value.setValue(fVal); assertEquals(fVal, value.floatValue()); assertEquals((double) fVal, value.doubleValue()); assertEquals(fVal, value.bigDecimalValue().floatValue()); value.setValue(A_DOUBLE); assertEquals(A_DOUBLE, value.doubleValue()); assertEquals(A_DOUBLE, value.bigDecimalValue().doubleValue()); value.setValue(null); checkNullDecimal(value); }
@Test public void testBinaryDecimals() throws Exception { IonDatagram dg = loadTestFile("good/decimalOneDotZero.10n"); assertEquals(1, dg.size()); IonDecimal value = (IonDecimal) dg.get(0); BigDecimal dec = value.bigDecimalValue(); checkDecimal(10, 1, dec); assertEquals(1, dec.intValue()); dg = loadTestFile("good/decimalNegativeOneDotZero.10n"); assertEquals(1, dg.size()); value = (IonDecimal) dg.get(0); dec = value.bigDecimalValue(); checkDecimal(-10, 1, dec); assertEquals(-1, dec.intValue()); }
@Test public void testScale() { final BigDecimal one_00 = new BigDecimal("1.00"); assertEquals(1, one_00.intValue()); assertEquals(100, one_00.unscaledValue().intValue()); assertEquals(2, one_00.scale()); IonDecimal value = (IonDecimal) oneValue("1.00"); assertEquals(one_00, value.bigDecimalValue()); }
public void testNegativeZero(int scale, IonDecimal actual) { assertEquals(-0f, actual.floatValue()); assertEquals(-0d, actual.doubleValue()); BigDecimal bd = actual.bigDecimalValue(); Decimal dec = actual.decimalValue(); assertEquals(0, BigDecimal.ZERO.compareTo(bd)); checkDecimal(0, scale, bd); checkDecimal(0, scale, dec); assertEquals(0, Decimal.NEGATIVE_ZERO.compareTo(dec)); assertTrue(dec.isNegativeZero()); }
public static void checkNullDecimal(IonDecimal value) { assertSame(IonType.DECIMAL, value.getType()); assertTrue("isNullValue is false", value.isNullValue()); try { value.floatValue(); fail("Expected NullValueException"); } catch (NullValueException e) { } try { value.doubleValue(); fail("Expected NullValueException"); } catch (NullValueException e) { } assertNull("bigDecimalValue() isn't null", value.bigDecimalValue()); }
@Test public void testDecimals() { IonDecimal value = (IonDecimal) oneValue("1.0"); assertSame(IonType.DECIMAL, value.getType()); assertFalse(value.isNullValue()); assertArrayEquals(new String[0], value.getTypeAnnotations()); assertEquals(1.0F, value.floatValue()); assertEquals(1.0D, value.doubleValue()); assertEquals(new BigDecimal(1).setScale(1), value.bigDecimalValue()); // TODO more... value = (IonDecimal) oneValue("a::1.0"); assertFalse(value.isNullValue()); checkAnnotation("a", value); // Ensure that annotation makes it through value mods modifyDecimal(value); checkAnnotation("a", value); }
@Test public void testSetValue() { IonDecimal value = decimal("1.23"); value.setValue(123); checkDecimal(123, 0, value.bigDecimalValue()); }