Exemplo n.º 1
0
  public void testStoreValue() {
    Int64Array empty = Int64Array.make(0);
    Int64Array tri = Int64Array.make(3);

    // Store integer values within spec
    tri.storeValue(0, IntegerValue.make(Long.MIN_VALUE));
    assertTrue(tri.int64At(0) == Long.MIN_VALUE);
    tri.storeValue(1, IntegerValue.make(1));
    assertEquals(tri.int64At(1), 1);
    tri.storeValue(2, IntegerValue.make(Long.MAX_VALUE));
    assertTrue(tri.int64At(2) == Long.MAX_VALUE);

    // Store integer values outside of spec
    try {
      tri.storeValue(0, IntegerValue.make(Long.MIN_VALUE).minus(IntegerValue.one()));
      fail("MIN_VALUE - 1");
    } catch (IllegalArgumentException e) {
      // expected
    }
    try {
      tri.storeValue(2, IntegerValue.make(Long.MAX_VALUE).plus(IntegerValue.one()));
      fail("MAX_VALUE + 1");
    } catch (IllegalArgumentException e) {
      // expected
    }

    // Store outside array boundary
    try {
      tri.storeValue(-1, IntegerValue.make(1));
      fail("-1");
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    try {
      tri.storeValue(3, IntegerValue.make(1));
      fail("3");
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    try {
      empty.storeValue(0, IntegerValue.make(1));
      fail("0");
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    // non-compatible store
    try {
      tri.storeValue(0, IEEE64Value.make(1.1));
      fail("classCast");
    } catch (ClassCastException e) {
      // expected
    }

    // Null value
    try {
      tri.storeValue(0, null);
      fail("null");
    } catch (NullPointerException e) {
      // expected
    }
  }