@Test
  public void appenderTest() {
    final CountingAppender appender = new CountingAppender();
    final StringAppender stringAppender = new StringAppender();

    log4jLogger.addAppender(appender);
    log4jLogger.addAppender(stringAppender);
    log4jLogger.info(MESSAGE);

    org.jboss.logging.Logger.getLogger(getClass()).info(JBL_MESSAGE);
    java.util.logging.Logger.getLogger(getClass().getName()).info(JUL_MESSAGE);

    final String stringFormat = "This is a %s format test.";
    org.jboss.logging.Logger.getLogger(getClass()).infof(stringFormat, "string");

    final String msgFormat = "This is a {} format test.";
    org.jboss.logging.Logger.getLogger(getClass()).infof(stringFormat, "message");

    assertEquals(5, appender.counter);
    assertEquals(5, stringAppender.messages.size());
    assertEquals(MESSAGE, stringAppender.messages.get(0));
    assertEquals(JBL_MESSAGE, stringAppender.messages.get(1));
    assertEquals(JUL_MESSAGE, stringAppender.messages.get(2));
    assertFalse(stringFormat.equals(stringAppender.messages.get(3)));
    assertFalse(msgFormat.equals(stringAppender.messages.get(4)));
  }
Exemplo n.º 2
0
  @Test
  public void testDiffRatios() {
    logger.info("\ntesting diffRatios()");
    double[] input = null;
    double[] result = null;
    assertEquals(0, MathUtil.diffRatios(input).length);
    input = new double[] {};
    assertEquals(0, MathUtil.diffRatios(input).length);
    input = new double[] {1};
    assertEquals(0, MathUtil.diffRatios(input).length);

    input = new double[] {1, 2};
    result = MathUtil.diffRatios(input);
    assertEquals(1, result.length);
    assertEquals(2.0, result[0], 0.0);

    input = new double[] {1, 2, 1, 5};
    result = MathUtil.diffRatios(input);
    assertEquals(3, result.length);
    assertEquals(2.0, result[0], 0.0);
    assertEquals(0.5, result[1], 0.0);
    assertEquals(5.0, result[2], 0.0);

    input = new double[] {1, 2, 0, 5, 8};
    result = MathUtil.diffRatios(input);
    logger.debug(ListArrayUtil.arrayToString(result));
    assertEquals(true, Double.isInfinite(result[2]));
    assertEquals(false, Double.isNaN(result[2]));
  }
Exemplo n.º 3
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));
  }
Exemplo n.º 4
0
  @Test
  public void testSeqInteger() {
    logger.info("\ntesting seqInteger()");

    Integer[] result = null;

    // with start == end --> length 1
    result = MathUtil.seqInteger(0, 0);
    assertEquals(1, result.length);
    assertEquals(true, ListArrayUtil.haveSameElements(result, new Integer[] {0}));
    result = MathUtil.seqInteger(4, 4);
    assertEquals(1, result.length);
    assertEquals(true, ListArrayUtil.haveSameElements(result, new Integer[] {4}));

    // with start less than end
    result = MathUtil.seqInteger(0, 1);
    assertEquals(2, result.length);
    assertEquals(true, ListArrayUtil.haveSameElements(result, new Integer[] {0, 1}));

    result = MathUtil.seqInteger(2, 5);
    assertEquals(4, result.length);
    assertEquals(true, ListArrayUtil.haveSameElements(result, new Integer[] {2, 3, 4, 5}));

    result = MathUtil.seqInteger(-7, -4);
    assertEquals(4, result.length);
    assertEquals(true, ListArrayUtil.haveSameElements(result, new Integer[] {-7, -6, -5, -4}));

    result = MathUtil.seqInteger(-7, 2);
    assertEquals(10, result.length);
    assertEquals(
        true,
        ListArrayUtil.haveSameElements(
            result, new Integer[] {-7, -6, -5, -4, -3, -2, -1, 0, 1, 2}));

    // now try start greater than end
    result = MathUtil.seqInteger(5, 2);
    assertEquals(4, result.length);
    // logger.debug(ListArrayUtil.arrayToString(result));
    assertEquals(true, ListArrayUtil.haveSameElements(result, new Integer[] {5, 4, 3, 2}));

    result = MathUtil.seqInteger(5, -2);
    assertEquals(8, result.length);
    // logger.debug(ListArrayUtil.arrayToString(result));
    assertEquals(
        true, ListArrayUtil.haveSameElements(result, new Integer[] {5, 4, 3, 2, 1, 0, -1, -2}));

    result = MathUtil.seqInteger(-2, -5);
    assertEquals(4, result.length);
    assertEquals(true, ListArrayUtil.haveSameElements(result, new Integer[] {-2, -3, -4, -5}));

    logger.debug(ListArrayUtil.arrayToString(MathUtil.seqInteger(0, 40)));
  }
Exemplo n.º 5
0
  @Test
  public void testCumSumList_DoubleList() {
    logger.info("\ntesting cumsumList(List<Double> input)");
    List<Double> result = null;
    List<Double> input = null;
    assertEquals(0, MathUtil.cumsumList(input).size());
    assertEquals(true, MathUtil.cumsumList(input).isEmpty());
    input = new ArrayList<Double>();
    assertEquals(0, MathUtil.cumsumList(input).size());
    assertEquals(true, MathUtil.cumsumList(input).isEmpty());

    input.add(4.0);
    result = MathUtil.cumsumList(input);
    assertEquals(1, result.size());
    assertEquals(4.0, result.get(0), 0.0);

    input.add(1.0);
    input.add(8.0);
    input.add(-3.0);
    result = MathUtil.cumsumList(input);
    assertEquals(4, result.size());
    assertEquals(4.0, result.get(0), 0.0);
    assertEquals(5.0, result.get(1), 0.0);
    assertEquals(13.0, result.get(2), 0.0);
    assertEquals(10.0, result.get(3), 0.0);

    List input2 = new ArrayList<Integer>();
    input2.add(1);
    input2.add(2);
    // List result2 = ListArrayUtil.cumsumList(input2);
    // logger.debug(toolbox.ListArrayUtil.listToString(input2));
  }
Exemplo n.º 6
0
  @Test
  public void testProd_List_Double_Range() {
    logger.info("\ntesting prod(List<Double> list, int start, int end)");

    List<Double> input = null;
    assertEquals(0.0, MathUtil.prod(input, 0, 0), 0.0);

    input = new ArrayList<Double>();
    assertEquals(0.0, MathUtil.prod(input, 0, 0), 0.0);

    input.add(4.0);
    input.add(1.0);
    input.add(.5);
    input.add(27.0);
    assertEquals(4.0, MathUtil.prod(input, 0, 0), 0.0);
    assertEquals(4.0, MathUtil.prod(input, 0, 1), 0.0);
    assertEquals(2.0, MathUtil.prod(input, 0, 2), 0.0);
    assertEquals(54.0, MathUtil.prod(input, 0, 3), 0.0);

    assertEquals(1.0, MathUtil.prod(input, 1, 1), 0.0);
    assertEquals(0.5, MathUtil.prod(input, 1, 2), 0.0);
    assertEquals(13.5, MathUtil.prod(input, 1, 3), 0.0);

    assertEquals(54.0, MathUtil.prod(input, -1, 4), 0.0);
    assertEquals(54.0, MathUtil.prod(input, 0, 4), 0.0);

    assertEquals(54.0, MathUtil.prod(input, 3, 0), 0.0);
    assertEquals(54.0, MathUtil.prod(input, 4, -1), 0.0);
  }
Exemplo n.º 7
0
  @Test
  public void testProd_double_array_Range() {
    logger.info("\ntesting prod(List<Double> list, int start, int end)");

    double[] input = null;
    assertEquals(0.0, MathUtil.prod(input), 0.0);

    input = new double[] {};
    assertEquals(0.0, MathUtil.prod(input), 0.0);

    input = new double[] {4, 1.0, 0.5, 27.0};
    assertEquals(4.0, MathUtil.prod(input, 0, 0), 0.0);
    assertEquals(4.0, MathUtil.prod(input, 0, 1), 0.0);
    assertEquals(2.0, MathUtil.prod(input, 0, 2), 0.0);
    assertEquals(54.0, MathUtil.prod(input, 0, 3), 0.0);

    assertEquals(1.0, MathUtil.prod(input, 1, 1), 0.0);
    assertEquals(0.5, MathUtil.prod(input, 1, 2), 0.0);
    assertEquals(13.5, MathUtil.prod(input, 1, 3), 0.0);

    assertEquals(54.0, MathUtil.prod(input, -1, 4), 0.0);
    assertEquals(54.0, MathUtil.prod(input, 0, 4), 0.0);

    assertEquals(54.0, MathUtil.prod(input, 3, 0), 0.0);
    assertEquals(54.0, MathUtil.prod(input, 4, -1), 0.0);
  }
Exemplo n.º 8
0
  @Test
  public void itLogsAStartupMessage() {
    Logger.logStartup(8399, "/some/dir/", "someapp.jar");

    assertTrue(output.toString().contains("8399"));
    assertTrue(output.toString().contains("/some/dir/"));
    assertTrue(output.toString().contains("someapp.jar"));
  }
  @Test
  public void rootAppenderTest() {
    final CountingAppender appender = new CountingAppender();
    final StringAppender stringAppender = new StringAppender();

    root.addAppender(appender);
    root.addAppender(stringAppender);
    root.info(ROOT_LOGGER_MSG);

    final String msg = JBL_MESSAGE + " root logger";
    org.jboss.logmanager.Logger.getLogger(JBossLogManagerFacade.JBL_ROOT_NAME).info(msg);
    org.jboss.logging.Logger.getLogger(JBossLogManagerFacade.JBL_ROOT_NAME).info(msg);

    assertEquals(3, appender.counter);
    assertEquals(3, stringAppender.messages.size());
    assertEquals(ROOT_LOGGER_MSG, stringAppender.messages.get(0));
    assertEquals(msg, stringAppender.messages.get(1));
    assertEquals(msg, stringAppender.messages.get(2));
  }
Exemplo n.º 10
0
  @Test
  public void testSD_double_Array() {
    logger.info("\ntesting sd(double[] input)");
    double[] input = null;
    assertEquals(Double.NaN, MathUtil.sd(input), 0.0);
    assertEquals(Double.NaN, MathUtil.sd(new double[] {}), 0.0);
    assertEquals(Double.NaN, MathUtil.sd(new double[] {1.0}), 0.0);

    assertEquals(1.581139, MathUtil.sd(new double[] {1.0, 2.0, 3.0, 4.0, 5.0}), 0.0001);
  }
Exemplo n.º 11
0
  @Test
  public void testSD_int_array() {
    logger.info("\ntesting sd(int[] input)");
    int[] input = null;
    assertEquals(Double.NaN, MathUtil.sd(input), 0.0);
    assertEquals(Double.NaN, MathUtil.sd(new int[] {}), 0.0);
    assertEquals(Double.NaN, MathUtil.sd(new int[] {1}), 0.0);

    assertEquals(1.581139, MathUtil.sd(new int[] {1, 2, 3, 4, 5}), 0.0001);
  }
Exemplo n.º 12
0
  @Test
  public void testSetDecimalPlaces() {
    logger.info("\ntesting setDecimalPlaces()");
    assertEquals(10.21, MathUtil.setDecimalPlaces(10.2112, 2), 0.0);
    assertEquals(3.14159, MathUtil.setDecimalPlaces(Math.PI, 5), 0.0);
    assertEquals(2.718, MathUtil.setDecimalPlaces(Math.E, 3), 0.0);
    assertEquals(2.718281, MathUtil.setDecimalPlaces(Math.E, 6), 0.0);
    // assertEquals(2.718281828459, MathUtil.setDecimalPlaces(Math.E, 12), 0.0);

    // TODO:  complete testing
  }
Exemplo n.º 13
0
  @Test
  public void testCov_double_array() {
    logger.info("\ntesting cov(double[] x, double[] y)");
    assertEquals(Double.NaN, MathUtil.cov(null, null), 0.0);
    assertEquals(Double.NaN, MathUtil.cov(new double[0], null), 0.0);
    assertEquals(Double.NaN, MathUtil.cov(new double[] {1.0, 2.0}, null), 0.0);
    assertEquals(Double.NaN, MathUtil.cov(null, new double[] {1.0, 2.0}), 0.0);
    assertEquals(Double.NaN, MathUtil.cov(null, new double[0]), 0.0);

    assertEquals(Double.NaN, MathUtil.cov(new double[] {1, 2}, new double[] {1, 2, 3}), 0.0);

    assertEquals(0.5, MathUtil.cov(new double[] {1, 2}, new double[] {1, 2}), 0.0);
  }
Exemplo n.º 14
0
  @Test
  public void itLogsRequestResponseTransaction() throws IOException {
    Request request = new Request("GET", "/mock.html", null, "");
    Response response = new Response("200 OK", null, "Hello".getBytes());
    Date socketOpenTime = new Date();

    Files.deleteIfExists(Paths.get("public/logs"));
    Logger.logBasic(request, response, socketOpenTime, "public/");

    assertArrayEquals(
        (socketOpenTime.toString() + " 'GET /mock.html HTTP/1.1' 200 OK\n").getBytes(),
        Files.readAllBytes(Paths.get("public/logs")));
  }
Exemplo n.º 15
0
  @Test
  public void testSummary_double_array() {
    logger.info("\ntesting summary(double[] array)");
    double[] input = null;

    input = new double[] {1, 2, 3, 4};
    Summary result = MathUtil.summary(input);
    assertEquals(1.0, result.min, 0.0);
    assertEquals(2.5, result.median, 0.0);
    assertEquals(2.5, result.mean, 0.0);
    assertEquals(4, result.max, 0.0);
    assertEquals(1.290994, result.sd, 0.0001);
  }
  @Test
  public void duplicateAppenderTest() {
    final CountingAppender appender = new CountingAppender();
    final StringAppender stringAppender = new StringAppender();

    root.addAppender(appender);
    root.addAppender(stringAppender);
    root.info(ROOT_LOGGER_MSG);

    log4jLogger.addAppender(stringAppender);
    log4jLogger.info(MESSAGE);

    org.jboss.logging.Logger.getLogger(getClass()).info(JBL_MESSAGE);

    assertEquals(3, appender.counter);
    assertEquals(5, stringAppender.messages.size());
    assertEquals(ROOT_LOGGER_MSG, stringAppender.messages.get(0));
    assertEquals(MESSAGE, stringAppender.messages.get(1));
    assertEquals(MESSAGE, stringAppender.messages.get(2));
    assertEquals(JBL_MESSAGE, stringAppender.messages.get(3));
    assertEquals(JBL_MESSAGE, stringAppender.messages.get(4));
  }
  @Test
  public void levelChangeTest() {
    final CountingAppender appender = new CountingAppender();
    log4jLogger.addAppender(appender);
    log4jLogger.setLevel(Level.INFO);

    log4jLogger.error(MESSAGE);
    log4jLogger.fatal(MESSAGE);
    log4jLogger.warn(MESSAGE);
    log4jLogger.info(MESSAGE);
    log4jLogger.debug(MESSAGE);
    log4jLogger.trace(MESSAGE);

    assertEquals(4, appender.counter);
  }
Exemplo n.º 18
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)));
  }
Exemplo n.º 19
0
  @Test
  public void testIntToDouble() {
    logger.info("\ntesting intoToDouble()");
    assertEquals(MathUtil.intToDouble(null).length, 0);
    assertEquals(MathUtil.intToDouble(new int[0]).length, 0);
    assertEquals(MathUtil.intToDouble(new int[] {}).length, 0);

    double[] result = null;
    result = MathUtil.intToDouble(new int[] {1, 2, 3});
    assertEquals(result.length, 3);
    assertEquals(result[0], 1.0, 0.0);
    assertEquals(result[1], 2.0, 0.0);
    assertEquals(result[2], 3.0, 0.0);
  }
Exemplo n.º 20
0
  @Test
  public void testCor_double_array() {
    logger.info("\ntesting cor(double[] x, double[] y)");
    assertEquals(Double.NaN, MathUtil.cor(null, null), 0.0);
    assertEquals(Double.NaN, MathUtil.cor(new double[0], null), 0.0);
    assertEquals(Double.NaN, MathUtil.cor(new double[] {1.0, 2.0}, null), 0.0);
    assertEquals(Double.NaN, MathUtil.cor(null, new double[] {1.0, 2.0}), 0.0);
    assertEquals(Double.NaN, MathUtil.cor(null, new double[0]), 0.0);

    assertEquals(Double.NaN, MathUtil.cor(new double[] {1.0}, new double[] {1.0}), 0.0);
    assertEquals(Double.NaN, MathUtil.cor(new double[] {1, 2}, new double[] {1, 2, 3}), 0.0);

    assertEquals(1.0, MathUtil.cor(new double[] {1, 2}, new double[] {1, 2}), 0.00000001);
    System.out.println(Math.sqrt(-1));
  }
Exemplo n.º 21
0
  @Test
  public void testSD_List_Double() {
    logger.info("\ntesting sd(List<Double> input)");
    List<Double> input = null;
    assertEquals(Double.NaN, MathUtil.sd(input), 0.0);

    input = new ArrayList<Double>();
    assertEquals(Double.NaN, MathUtil.sd(input), 0.0);
    input.add(1.0);
    assertEquals(Double.NaN, MathUtil.sd(input), 0.0);
    input.add(2.0);
    input.add(3.0);
    input.add(4.0);
    input.add(5.0);
    assertEquals(1.581139, MathUtil.sd(input), 0.0001);
  }
Exemplo n.º 22
0
  @Test
  public void testSummary_List_Double() {
    logger.info("\ntesting summary(List<Double> list)");
    List<Double> input = null;
    Summary result = null;
    result = MathUtil.summary(input);
    if (result == null) {
      fail("summary was null");
    }
    /*public double min;
    public double firstQ;
    public double median;
    public double mean;
    public double thirdQ;
    public double max;
    public double sd*/
    assertEquals(0.0, result.min, 0.0);
    assertEquals(0.0, result.firstQ, 0.0);
    assertEquals(0.0, result.median, 0.0);
    assertEquals(0.0, result.mean, 0.0);
    assertEquals(0.0, result.thirdQ, 0.0);
    assertEquals(0.0, result.max, 0.0);
    assertEquals(0.0, result.sd, 0.0);

    input = new ArrayList<Double>();
    result = MathUtil.summary(input);
    assertEquals(0.0, result.min, 0.0);
    assertEquals(0.0, result.firstQ, 0.0);
    assertEquals(0.0, result.median, 0.0);
    assertEquals(0.0, result.mean, 0.0);
    assertEquals(0.0, result.thirdQ, 0.0);
    assertEquals(0.0, result.max, 0.0);
    assertEquals(0.0, result.sd, 0.0);

    input.add(1.0);
    input.add(2.0);
    input.add(3.0);
    input.add(4.0);
    result = MathUtil.summary(input);
    assertEquals(1.0, result.min, 0.0);
    // assertEquals(1.75, result.firstQ, 0.0);
    assertEquals(2.5, result.median, 0.0);
    assertEquals(2.5, result.mean, 0.0);
    // assertEquals(3.25, result.thirdQ, 0.0);
    assertEquals(4.0, result.max, 0.0);
    assertEquals(1.290994, result.sd, 0.0001);
  }
Exemplo n.º 23
0
 @Test
 public void testSum_List_Double() {
   logger.info("\ntesting sum(List<Double> list)");
   List<Double> l = new ArrayList<Double>();
   assertEquals(0.0, MathUtil.sum(null), 0.0);
   assertEquals(0.0, MathUtil.sum(l), 0.0);
   l.add(27.0);
   assertEquals(27.0, MathUtil.sum(l), 0.0);
   l.add(-5.0);
   assertEquals(22.0, MathUtil.sum(l), 0.0);
   l.remove(27.0);
   assertEquals(-5.0, MathUtil.sum(l), 0.0);
   l.add(1.0);
   l.add(2.0);
   l.add(48.0);
   assertEquals(46.0, MathUtil.sum(l), 0.0);
 }
Exemplo n.º 24
0
  @Test
  public void testProd_List_Double() {
    logger.info("\ntesting prod(List<Double> list)");
    List<Double> input = null;
    assertEquals(0.0, MathUtil.prod(input), 0.0);

    input = new ArrayList<Double>();
    assertEquals(0.0, MathUtil.prod(input), 0.0);

    input.add(4.0);
    assertEquals(4.0, MathUtil.prod(input), 0.0);
    input.add(1.0);
    assertEquals(4.0, MathUtil.prod(input), 0.0);
    input.add(.5);
    assertEquals(2.0, MathUtil.prod(input), 0.0);
    input.add(27.0);
    assertEquals(54.0, MathUtil.prod(input), 0.0);
  }
Exemplo n.º 25
0
  @Test
  public void testProd_double_array() {
    logger.info("\ntesting prod(List<Double> list)");
    double[] input = null;
    assertEquals(0.0, MathUtil.prod(input), 0.0);

    input = new double[] {};
    assertEquals(0.0, MathUtil.prod(input), 0.0);

    input = new double[] {4};
    assertEquals(4.0, MathUtil.prod(input), 0.0);
    input = new double[] {4, 1.0};
    assertEquals(4.0, MathUtil.prod(input), 0.0);
    input = new double[] {4, 1.0, 0.5};
    assertEquals(2.0, MathUtil.prod(input), 0.0);
    input = new double[] {4, 1.0, 0.5, 27.0};
    assertEquals(54.0, MathUtil.prod(input), 0.0);
  }
Exemplo n.º 26
0
 @Test
 public void testLogBase2() {
   logger.debug("\ntesting logBase2()");
   logger.debug(MathUtil.logBase2(1));
   logger.debug(MathUtil.logBase2(2));
   logger.debug(MathUtil.logBase2(3));
   logger.debug(MathUtil.logBase2(4));
   logger.debug(MathUtil.logBase2(5));
   logger.debug(MathUtil.logBase2(6));
   logger.debug(MathUtil.logBase2(7));
   logger.debug(MathUtil.logBase2(8));
   logger.debug(MathUtil.logBase2(9));
 }
Exemplo n.º 27
0
  @Test
  public void testSum_int_array() {
    logger.info("\ntesting sum(int[] input, int...endPoints)");
    int[] input = null;
    assertEquals(0, MathUtil.sum(input));
    assertEquals(0, MathUtil.sum(input, 0));
    assertEquals(0, MathUtil.sum(input, 0, 57, 3));

    input = new int[0];
    assertEquals(0, MathUtil.sum(input));
    assertEquals(0, MathUtil.sum(input, 0));
    assertEquals(0, MathUtil.sum(input, 0, 57, 3));

    input = new int[] {1, 2, 3, 4};
    assertEquals(10, MathUtil.sum(input), 0.0);
    assertEquals(3, MathUtil.sum(input, 0, 1));
    assertEquals(3, MathUtil.sum(input, 1, 0));
    assertEquals(6, MathUtil.sum(input, 0, 2));
    assertEquals(10, MathUtil.sum(input, 0, 3));
    assertEquals(10, MathUtil.sum(input, 0, 4));

    assertEquals(2, MathUtil.sum(input, 1, 1));
    assertEquals(5, MathUtil.sum(input, 1, 2));
    assertEquals(9, MathUtil.sum(input, 1, 3));
    assertEquals(9, MathUtil.sum(input, 3, 1));

    // with indeces out of bounds
    assertEquals(9, MathUtil.sum(input, 4, 1));
    assertEquals(9, MathUtil.sum(input, 1, 4));
    assertEquals(10, MathUtil.sum(input, -8, 45));
    assertEquals(10, MathUtil.sum(input, 45, -8));

    // binary
    input = new int[] {0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0};
    assertEquals(5, MathUtil.sum(input));
  }
Exemplo n.º 28
0
  @Test
  public void testCheckEndPoints() {
    logger.info("\ntesting checkEndPoints()");
    int[] input = null;
    int[] result = null;

    // null and empty arrays
    result = MathUtil.checkEndPoints(0, 1, input);
    assertEquals(2, result.length);
    assertEquals(0, result[0]);
    assertEquals(1, result[1]);

    result = MathUtil.checkEndPoints(1, 1, input);
    assertEquals(2, result.length);
    assertEquals(1, result[0]);
    assertEquals(1, result[1]);

    result = MathUtil.checkEndPoints(4, 4, input);
    assertEquals(2, result.length);
    assertEquals(4, result[0]);
    assertEquals(4, result[1]);

    // TODO:  deal with case where defaults are switched
    // or should it give an error since it is a programmer error
    result = MathUtil.checkEndPoints(2, 1, input);
    assertEquals(2, result.length);
    assertEquals(1, result[0]);
    assertEquals(2, result[1]);

    // TODO:  test with array of one element

    // array of two elements
    input = new int[] {4, 8};
    result = MathUtil.checkEndPoints(4, 10, input);
    assertEquals(2, result.length);
    assertEquals(4, result[0]);
    assertEquals(8, result[1]);

    input = new int[] {4, 8, 20}; // third element should be ignored
    result = MathUtil.checkEndPoints(4, 10, input);
    assertEquals(2, result.length);
    assertEquals(4, result[0]);
    assertEquals(8, result[1]);

    input = new int[] {4, 8};
    result = MathUtil.checkEndPoints(0, 1, input);
    assertEquals(2, result.length);
    assertEquals(0, result[0]);
    assertEquals(1, result[1]);

    input = new int[] {-4, -8};
    result = MathUtil.checkEndPoints(0, 1, input);
    assertEquals(2, result.length);
    assertEquals(0, result[0]);
    assertEquals(1, result[1]);

    input = new int[] {-1, 2};
    result = MathUtil.checkEndPoints(0, 1, input);
    assertEquals(2, result.length);
    logger.debug(ListArrayUtil.arrayToString(result));
    assertEquals(0, result[0]);
    assertEquals(1, result[1]);

    input = new int[] {-1, 2};
    result = MathUtil.checkEndPoints(1, 0, input);
    assertEquals(2, result.length);
    logger.debug(ListArrayUtil.arrayToString(result));
    assertEquals(0, result[0]);
    assertEquals(1, result[1]);

    input = new int[] {2 - 1};
    result = MathUtil.checkEndPoints(0, 1, input);
    assertEquals(2, result.length);
    assertEquals(0, result[0]);
    assertEquals(1, result[1]);

    input = new int[] {2, -1};
    result = MathUtil.checkEndPoints(1, 0, input);
    assertEquals(2, result.length);
    assertEquals(0, result[0]);
    assertEquals(1, result[1]);

    // TODO: more testing
  }
 @Before
 public void clearAppenders() {
   log4jLogger.removeAllAppenders();
   root.removeAllAppenders();
 }
Exemplo n.º 30
0
 @Test
 public void testMax_Int_Array() {
   logger.info("\ntesting max(int[] array)");
   // TODO:  fill in
 }