Example #1
0
  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());
  }
Example #2
0
  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);
  }
Example #3
0
  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());
  }
Example #4
0
  @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);
  }