Ejemplo n.º 1
0
  @Test
  public void testSum_double_array() {
    logger.info("\ntesting sum(double[] input, int...endPoints)");
    double[] input = null;
    assertEquals(0.0, MathUtil.sum(input), 0.0);
    assertEquals(0.0, MathUtil.sum(input, 0), 0.0);
    assertEquals(0.0, MathUtil.sum(input, 0, 57, 3), 0.0);

    input = new double[] {1.0, 2.0, 3.0, 4.0};
    assertEquals(10.0, MathUtil.sum(input), 0.0);
    assertEquals(3.0, MathUtil.sum(input, 0, 1), 0.0);
    assertEquals(6.0, MathUtil.sum(input, 0, 2), 0.0);
    assertEquals(10.0, MathUtil.sum(input, 0, 3), 0.0);
    assertEquals(10.0, MathUtil.sum(input, 0, 4), 0.0);

    assertEquals(2.0, MathUtil.sum(input, 1, 1), 0.0);
    assertEquals(5.0, MathUtil.sum(input, 1, 2), 0.0);
    assertEquals(9.0, MathUtil.sum(input, 1, 3), 0.0);

    // with indeces out of bounds
    assertEquals(9.0, MathUtil.sum(input, 1, 4), 0.0);
    assertEquals(9.0, MathUtil.sum(input, 4, 1), 0.0);

    input =
        new double[] {
          1.3310000000000004, 1.3310000000000004, 1.3310000000000004, 1.3310000000000004
        };
    double[] cumBins = MathUtil.cumProd(input, true);
    logger.debug(ListArrayUtil.arrayToString(cumBins));
    int regularContribution = 1;
    logger.debug(cumBins[0] + regularContribution * MathUtil.sum(cumBins, 1, cumBins.length - 1));
  }
Ejemplo n.º 2
0
  @Test
  public void testCumprod_double_array() {
    logger.info("\n testing cumProd(double[] array, boolean...reverse)");
    double[] input = null;
    double[] result = null;
    result = MathUtil.cumProd(input);
    assertEquals(0, result.length);

    input = new double[] {};
    assertEquals(0, MathUtil.cumProd(input).length);

    input = new double[] {1.0, 2.0, 3.0, 1.0, 2.0, -1.0, -1.0};
    result = MathUtil.cumProd(input);
    assertEquals(7, result.length);
    assertEquals(1.0, result[0], 1.0);
    assertEquals(2.0, result[1], 1.0);
    assertEquals(6.0, result[2], 1.0);
    assertEquals(6.0, result[3], 1.0);
    assertEquals(12.0, result[4], 1.0);
    assertEquals(-12.0, result[5], 1.0);
    assertEquals(12.0, result[6], 1.0);

    result = MathUtil.cumProd(input, true);
    assertEquals(7, result.length);
    assertEquals(-1.0, result[6], 1.0);
    assertEquals(1.0, result[5], 1.0);
    assertEquals(2.0, result[4], 1.0);
    assertEquals(2.0, result[3], 1.0);
    assertEquals(6.0, result[2], 1.0);
    assertEquals(12.0, result[1], 1.0);
    assertEquals(12.0, result[0], 1.0);

    input =
        new double[] {
          1.3310000000000004, 1.3310000000000004, 1.3310000000000004, 1.3310000000000004
        };
    logger.debug(ListArrayUtil.arrayToString(MathUtil.cumProd(input, true)));
  }