コード例 #1
0
  public void testGetNearestValueIndexInDoubleArrays() {
    double[] testArray1 = new double[] {1.0, 2.0, 3.0, 6.0, 8.0, 10.0, 13.0, 14.0, 15.0};
    double value = 2.8;

    int index = GlintHelpers.getNearestValueIndexInAscendingDoubleArray(value, testArray1);
    assertEquals(2, index);

    double[] testArray2 = new double[] {21.0, 20.0, 13.0, 6.0, 2.0, 1.0, 0.0};
    index = GlintHelpers.getNearestValueIndexInDescendingDoubleArray(value, testArray2);
    assertEquals(4, index);
  }
コード例 #2
0
  public void testGetMinMaxInDoubleArrays() {
    double[] testArray1 = new double[] {1.0, 2.0, 3.0, 6.0, 8.0, 10.0, 16.0, 14.0, 15.0};

    int index = GlintHelpers.getMaximumValueIndexInDoubleArray(testArray1);
    assertEquals(6, index);
    double value = GlintHelpers.getMaximumValueInDoubleArray(testArray1);
    assertEquals(16.0, value);

    double[] testArray2 = new double[] {21.0, 20.0, 13.0, 6.0, 2.0, -3.0, 0.0};
    index = GlintHelpers.getMinimumValueIndexInDoubleArray(testArray2);
    assertEquals(5, index);
    value = GlintHelpers.getMinimumValueInDoubleArray(testArray2);
    assertEquals(-3.0, value);
  }
コード例 #3
0
  public void testLinearInterpol() {
    double x1 = 1.5;
    double x2 = 2.0;
    double y1 = 2.4;
    double y2 = 4.2;

    double x = 1.5;
    double y = GlintHelpers.linearInterpol(x, x1, x2, y1, y2);
    assertEquals(2.4, y);

    x = 1.7;
    y = GlintHelpers.linearInterpol(x, x1, x2, y1, y2);
    assertEquals(3.12, y);

    x = 1.95;
    y = GlintHelpers.linearInterpol(x, x1, x2, y1, y2);
    assertEquals(4.02, y);

    x = 2.0;
    y = GlintHelpers.linearInterpol(x, x1, x2, y1, y2);
    assertEquals(4.2, y);
  }