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

    tri.storeInt64(0, Long.MIN_VALUE);
    assertEquals(tri.int64At(0), Long.MIN_VALUE);
    tri.storeInt64(1, (int) 1);
    assertEquals(tri.int64At(1), 1);
    tri.storeInt64(2, Long.MAX_VALUE);
    assertEquals(tri.int64At(2), Long.MAX_VALUE);

    try {
      tri.storeInt64(-1, (int) 1);
      fail("-1");
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    try {
      tri.storeInt64(3, (int) 1);
      fail("3");
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    try {
      empty.storeInt64(0, (int) 1);
      fail("0");
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
  }
Exemplo n.º 2
0
  public void testZeroElements() {
    Int64Array array = Int64Array.make(0);
    array.zeroElements(0, -1);
    AssertArrays.assertEquals(Int64Array.make(0), array);

    // zero all elements
    array = Int64Array.make(1);
    array.storeInt64(0, 1);
    array.zeroElements(0, -1);
    AssertArrays.assertEquals(Int64Array.make(new long[] {0}), array);

    array = AssertArrays.makeInt64Array12345();
    array.zeroElements();
    AssertArrays.assertEquals(Int64Array.make(new long[] {0, 0, 0, 0, 0}), array);

    array = AssertArrays.makeInt64Array12345();
    array.zeroElements(0, -1);
    AssertArrays.assertEquals(Int64Array.make(new long[] {0, 0, 0, 0, 0}), array);

    // zero subset of elements
    array = AssertArrays.makeInt64Array12345();
    array.zeroElements(1, -1);
    AssertArrays.assertEquals(Int64Array.make(new long[] {1, 0, 0, 0, 0}), array);

    array = AssertArrays.makeInt64Array12345();
    array.zeroElements(1, 2);
    AssertArrays.assertEquals(Int64Array.make(new long[] {1, 0, 0, 4, 5}), array);

    array = AssertArrays.makeInt64Array12345();
    array.zeroElements(4, 1);
    AssertArrays.assertEquals(Int64Array.make(new long[] {1, 2, 3, 4, 0}), array);

    // silently truncate from
    array = AssertArrays.makeInt64Array12345();
    // TODO should this actually throw an exception?
    array.zeroElements(5, -1);
    AssertArrays.assertEquals(AssertArrays.makeInt64Array12345(), array);

    // extend count outside range
    array = AssertArrays.makeInt64Array12345();
    try {
      array.zeroElements(4, 2);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
  }