コード例 #1
0
  public void testStoreValue() {
    IEEE64Array empty = IEEE64Array.make(0);
    IEEE64Array tri = IEEE64Array.make(3);

    tri.storeValue(0, IEEE64Value.make(Float.MIN_VALUE));
    assertTrue(tri.iEEE64At(0) == Float.MIN_VALUE);
    tri.storeValue(1, IEEE64Value.make(1.1));
    assertEquals(tri.iEEE64At(1), 1.1, DIFF);
    tri.storeValue(2, IEEE64Value.make(Float.MAX_VALUE));
    assertTrue(tri.iEEE64At(2) == Float.MAX_VALUE);

    tri.storeValue(0, IEEE64Value.make(Double.MIN_VALUE));
    assertTrue(tri.iEEE64At(0) == Double.MIN_VALUE);
    tri.storeValue(0, IEEE64Value.make(1.1));
    assertTrue(tri.iEEE64At(0) == 1.1);
    assertTrue(tri.iEEE64At(0) == 1.1);
    tri.storeValue(2, IEEE64Value.make(Double.MAX_VALUE));
    assertTrue(tri.iEEE64At(2) == Double.MAX_VALUE);

    try {
      tri.storeValue(-1, IEEE64Value.make(1.1f));
      fail("-1");
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    try {
      tri.storeValue(3, IEEE64Value.make(1.1f));
      fail("3");
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    try {
      empty.storeValue(0, IEEE64Value.make(1.1f));
      fail("0");
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    // Null value
    try {
      tri.storeValue(0, null);
      fail("null");
    } catch (NullPointerException e) {
      // expected
    }
  }
コード例 #2
0
  public void testIsEqual() {
    double[] floatE = new double[] {};
    double[] float1 = new double[] {1.1};
    double[] float12 = new double[] {1.1, 2.2};
    double[] float11 = new double[] {1.1, 1.1};

    assertTrue(IEEE64Array.make(floatE).isEqual(IEEE64Array.make(floatE)));
    assertTrue(IEEE64Array.make(float1).isEqual(IEEE64Array.make(float1)));
    assertTrue(IEEE64Array.make(float12).isEqual(IEEE64Array.make(float12)));
    assertFalse(IEEE64Array.make(float11).isEqual(IEEE64Array.make(float12)));
    assertFalse(IEEE64Array.make(floatE).isEqual(IEEE64Array.make(float12)));
    assertFalse(IEEE64Array.make(float1).isEqual(IEEE64Value.make(1.1f)));
    assertFalse(IEEE64Array.make(float12).isEqual(IEEE64Array.make(floatE)));
  }
コード例 #3
0
  public void testIndexPast() {
    int index = AssertArrays.makeIEEE64ArrayEmpty().indexPast(IEEE64Value.make(1.1), 0, 1);
    assertEquals(-1, index);

    index = AssertArrays.makeIEEE64Array1().indexPast(IEEE64Value.make(1.1), 0, 1);
    assertEquals(-1, index);

    index = AssertArrays.makeIEEE64Array1().indexPast(IEEE64Value.make(1.1), 0, 0);
    assertEquals(-1, index);

    index = AssertArrays.makeIEEE64Array12345().indexPast(IEEE64Value.make(1.1), 0, 1);
    assertEquals(1, index);

    index = AssertArrays.makeIEEE64Array12345().indexPast(IEEE64Value.make(1.1), 0, 2);
    assertEquals(2, index);

    index = AssertArrays.makeIEEE64Array12345().indexPast(IEEE64Value.make(1.1), 1, 1);
    assertEquals(1, index);

    index = AssertArrays.makeIEEE64Array12345().indexPast(IEEE64Value.make(5.5), 0, 1);
    assertEquals(0, index);

    index = AssertArrays.makeIEEE64Array12345().indexPast(IEEE64Value.make(5.5), 3, 1);
    assertEquals(3, index);

    index = AssertArrays.makeIEEE64Array12345().indexPast(IEEE64Value.make(5.5), 4, 1);
    assertEquals(-1, index);

    index = AssertArrays.makeIEEE64Array12321().indexPast(IEEE64Value.make(2.2), 0, 1);
    assertEquals(0, index);

    index = AssertArrays.makeIEEE64Array12321().indexPast(IEEE64Value.make(2.2), 0, 2);
    assertEquals(2, index);

    index = AssertArrays.makeIEEE64Array12321().indexPast(IEEE64Value.make(1.1), -1, -1);
    assertEquals(3, index);

    index = AssertArrays.makeIEEE64Array12321().indexPast(IEEE64Value.make(2.2), -1, -1);
    assertEquals(4, index);

    index = AssertArrays.makeIEEE64Array12321().indexPast(IEEE64Value.make(2.2), -1, 1);
    assertEquals(4, index);

    index = AssertArrays.makeIEEE64Array12321().indexPast(IEEE64Value.make(2.2), -1, 2);
    assertEquals(-1, index);

    index = AssertArrays.makeIEEE64Array12321().indexPast(IEEE64Value.make(2.2), -1, -2);
    assertEquals(2, index);

    index = AssertArrays.makeIEEE64Array12321().indexPast(IEEE64Value.make(2.2), -1, -3);
    assertEquals(0, index);

    index = AssertArrays.makeIEEE64Array12321().indexPast(IEEE64Value.make(2.2), -3, -1);
    assertEquals(2, index);

    index = AssertArrays.makeIEEE64Array12321().indexPast(IEEE64Value.make(1.1), -1, 1);
    assertEquals(-1, index);

    try {
      AssertArrays.makeIEEE64Array12321().indexPast(IEEE64Value.make(2.2), -6, 1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
  }
コード例 #4
0
  public void testStoreAll() {
    IEEE64Array array = IEEE64Array.make(0);
    array.storeAll(IEEE64Value.make(1.1));
    AssertArrays.assertEquals(IEEE64Array.make(0), array, DIFF);

    array = IEEE64Array.make(1);
    array.storeAll(IEEE64Value.make(1.1));
    AssertArrays.assertEquals(IEEE64Array.make(new double[] {1.1}), array, DIFF);

    array = IEEE64Array.make(3);
    array.storeAll(IEEE64Value.make(2.2));
    AssertArrays.assertEquals(IEEE64Array.make(new double[] {2.2, 2.2, 2.2}), array, DIFF);

    array = AssertArrays.makeIEEE64Array12345();
    array.storeAll(IEEE64Value.make(9.9), 2, 1);
    AssertArrays.assertEquals(
        IEEE64Array.make(new double[] {1.1, 9.9, 9.9, 4.4, 5.5}), array, DIFF);

    array = AssertArrays.makeIEEE64Array12345();
    array.storeAll(null, 2, 1);
    AssertArrays.assertEquals(
        IEEE64Array.make(new double[] {1.1, 0.0, 0.0, 4.4, 5.5}), array, DIFF);

    array = AssertArrays.makeIEEE64Array12345();
    array.storeAll(IEEE64Value.make(9.9), -1, 1);
    AssertArrays.assertEquals(
        IEEE64Array.make(new double[] {1.1, 9.9, 9.9, 9.9, 9.9}), array, DIFF);

    array = AssertArrays.makeIEEE64Array12345();
    array.storeAll(IEEE64Value.make(9.9), 2);
    AssertArrays.assertEquals(
        IEEE64Array.make(new double[] {9.9, 9.9, 3.3, 4.4, 5.5}), array, DIFF);

    array = AssertArrays.makeIEEE64Array12345();
    array.storeAll(IEEE64Value.make(9.9), 0, 1);
    AssertArrays.assertEquals(
        IEEE64Array.make(new double[] {1.1, 2.2, 3.3, 4.4, 5.5}), array, DIFF);

    array = AssertArrays.makeIEEE64Array12345();
    array.storeAll(IEEE64Value.make(9.9), 2, 1);
    AssertArrays.assertEquals(
        IEEE64Array.make(new double[] {1.1, 9.9, 9.9, 4.4, 5.5}), array, DIFF);

    array = AssertArrays.makeIEEE64Array12345();
    try {
      array.storeAll(IEEE64Value.make(9.9), 6);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    array = AssertArrays.makeIEEE64Array12345();
    try {
      array.storeAll(IEEE64Value.make(9.9), 4, 2);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    // Store incompatible type
    array = AssertArrays.makeIEEE64Array12345();
    try {
      array.storeAll(IntegerValue.make(9), 1);
      fail();
    } catch (ClassCastException e) {
      // expected
    }
  }
コード例 #5
0
  public void testIndexOf() {
    int index = AssertArrays.makeInt64ArrayEmpty().indexOf(IntegerValue.make(1), 0, 1);
    assertEquals(-1, index);

    index = AssertArrays.makeInt64Array1().indexOf(IntegerValue.make(1), 0, 1);
    assertEquals(0, index);

    index = AssertArrays.makeInt64Array1().indexOf(IntegerValue.make(1), 0, 0);
    assertEquals(-1, index);

    index = AssertArrays.makeInt64Array12345().indexOf(IntegerValue.make(1), 0, 1);
    assertEquals(0, index);

    index = AssertArrays.makeInt64Array12345().indexOf(IntegerValue.make(1), 0, 2);
    assertEquals(-1, index);

    index = AssertArrays.makeInt64Array12345().indexOf(IntegerValue.make(1), 1, 1);
    assertEquals(-1, index);

    index = AssertArrays.makeInt64Array12345().indexOf(IntegerValue.make(5), 0, 1);
    assertEquals(4, index);

    index = AssertArrays.makeInt64Array12321().indexOf(IntegerValue.make(2), 0, 1);
    assertEquals(1, index);

    index = AssertArrays.makeInt64Array12321().indexOf(IntegerValue.make(2), 0, 2);
    assertEquals(3, index);

    index = AssertArrays.makeInt64Array12321().indexOf(IntegerValue.make(1), -1, -1);
    assertEquals(4, index);

    index = AssertArrays.makeInt64Array12321().indexOf(IntegerValue.make(2), -1, -1);
    assertEquals(3, index);

    index = AssertArrays.makeInt64Array12321().indexOf(IntegerValue.make(2), -1, 1);
    assertEquals(-1, index);

    index = AssertArrays.makeInt64Array12321().indexOf(IntegerValue.make(2), -1, -2);
    assertEquals(1, index);

    index = AssertArrays.makeInt64Array12321().indexOf(IntegerValue.make(2), -1, -3);
    assertEquals(-1, index);

    index = AssertArrays.makeInt64Array12321().indexOf(IntegerValue.make(2), -3, -1);
    assertEquals(1, index);

    index = AssertArrays.makeInt64Array12321().indexOf(IntegerValue.make(2), -1, 1);
    assertEquals(-1, index);

    try {
      AssertArrays.makeInt64Array12321().indexOf(IntegerValue.make(2), -6, 1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    try {
      AssertArrays.makeInt64Array12321().indexOf(IEEE64Value.make(2.0f), -3, 1);
      fail();
    } catch (ClassCastException e) {
      // expected
    }
  }
コード例 #6
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
    }
  }