コード例 #1
0
ファイル: MainTest.java プロジェクト: ezhulkov/agrrrh.ru
  @Test
  public void testMean() {

    int values[] = new int[] {33, 16, 9, 7, 5, 9, 16, 14, 421};

    float mean1 = 0;
    float mean2 = 0;

    // simple
    for (int value : values) {
      mean1 += value;
    }
    mean1 /= values.length;

    // online
    for (int i = 0; i < values.length; i++) {
      mean2 = AgUtils.calcMeanValue(mean2, i, values[i]);
    }

    System.out.println(mean1);
    System.out.println(mean2);
  }
コード例 #2
0
ファイル: MainTest.java プロジェクト: ezhulkov/agrrrh.ru
  @Test
  public void testUtils() {

    for (int i = 0; i < 101; i++) {
      System.out.println(
          i
              + " "
              + serviceFacade
                  .getDeclinationManager()
                  .appendNumberEnding("подписчик", i, WordGender.MASCULINE, Declination.SECOND));
    }

    List<String> t = Arrays.asList("1", "2", "3", "4");
    Assert.assertEquals(AgUtils.subList(t, 0, 2).size(), 2);
    Assert.assertEquals(AgUtils.subList(t, 0, 10).size(), 4);
    Assert.assertEquals(AgUtils.subList(t, 1, 10).size(), 3);
    Assert.assertEquals(AgUtils.subList(t, 2, 10).size(), 2);
    Assert.assertEquals(AgUtils.subList(t, 3, 10).size(), 1);
    Assert.assertEquals(AgUtils.subList(t, 4, 10).size(), 0);

    Assert.assertEquals(AgUtils.normilezeHTML("<p style=''>123</p>345"), "123 345");
    Assert.assertEquals(AgUtils.normilezeHTML("<p style=\"123\">123</p>345"), "123 345");
    Assert.assertEquals(
        AgUtils.normilezeHTML("<A href=''>123</a> <P>1234</p> <a href=''>123</A> 5"),
        "<A href=''>123</a>  1234  <a href=''>123</A> 5");
    Assert.assertEquals(AgUtils.trimHTML("12345", 1), "1...");
    Assert.assertEquals(AgUtils.trimHTML("12345", 2), "12...");
    Assert.assertEquals(AgUtils.trimHTML("12345", 3), "123...");
    Assert.assertEquals(AgUtils.trimHTML("12345", 4), "1234...");
    Assert.assertEquals(AgUtils.trimHTML("12345", 5), "12345");
    Assert.assertEquals(AgUtils.trimHTML("<a>123</a> 234 <a>456</a> 567", 1), "<a>123</a>...");
    Assert.assertEquals(AgUtils.trimHTML("<a>123</a> 234 <a>456</a> 567", 2), "<a>123</a>...");
    Assert.assertEquals(AgUtils.trimHTML("<a>123</a> 234 <a>456</a> 567", 3), "<a>123</a>...");
    Assert.assertEquals(AgUtils.trimHTML("<a>123</a> 234 <a>456</a> 567", 4), "<a>123</a> ...");
    Assert.assertEquals(AgUtils.trimHTML("<a>123</a> 234 <a>456</a> 567", 5), "<a>123</a> 2...");
    Assert.assertEquals(AgUtils.trimHTML("<a>123</a> 234 <a>456</a> 567", 6), "<a>123</a> 23...");
    Assert.assertEquals(
        AgUtils.processTextBody("http://www.ya.ru", -1),
        "<a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a>");
    Assert.assertEquals(AgUtils.processTextBody("l=http://www.ya.ru", -1), "l=http://www.ya.ru");
    Assert.assertEquals(AgUtils.processTextBody("12345", 3), "123...");
    Assert.assertEquals(AgUtils.processTextBody("12345", 4), "1234...");
    Assert.assertEquals(AgUtils.processTextBody("12345", 5), "12345");
    Assert.assertEquals(
        AgUtils.processTextBody("http://www.ya.ru", 10),
        "<a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a>...");
    Assert.assertEquals(
        AgUtils.processTextBody("http://www.ya.ru?test=123", 10),
        "<a class='l_blue' target='_blank' href='http://www.ya.ru?test=123'>http://www.ya.ru?test=123</a>...");
    Assert.assertEquals(
        AgUtils.processTextBody(
            "http://www.yayayayayayayayayayayayayayayayayayayayayayayayayayayayayayayaya.ru", 10),
        "<a class='l_blue' target='_blank' href='http://www.yayayayayayayayayayayayayayayayayayayayayayayayayayayayayayayaya.ru'>http://www.yayayayayayayayayayayayayayayayayayayay...</a>...");
    Assert.assertEquals(
        AgUtils.processTextBody("http://www.ya.ru http://www.mail.ru", 50),
        "<a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a> <a class='l_blue' target='_blank' href='http://www.mail.ru'>http://www.mail.ru</a>");
    Assert.assertEquals(
        AgUtils.processTextBody("http://www.ya.ru", 3),
        "<a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a>...");
    Assert.assertEquals(
        AgUtils.processTextBody("1234 http://www.ya.ru", 10),
        "1234 <a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a>...");
    Assert.assertEquals(
        AgUtils.processTextBody("1234 http://www.ya.ru 1234", 27),
        "1234 <a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a> 1234");
    Assert.assertEquals(
        AgUtils.processTextBody("1234 http://www.ya.ru 1234", 25),
        "1234 <a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a> 123...");
    Assert.assertEquals(AgUtils.processTextBody("1234 http://www.ya.ru 1234", 4), "1234...");
    Assert.assertEquals(
        AgUtils.processTextBody("1234 http://www.ya.ru 1234", 6),
        "1234 <a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a>...");
    Assert.assertEquals(
        AgUtils.processTextBody(
            "<a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a>", 80),
        "<a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a>");

    Assert.assertFalse(AgUtils.isMarkupBroken(""));
    Assert.assertFalse(AgUtils.isMarkupBroken("<a>ttt</a>"));
    Assert.assertTrue(AgUtils.isMarkupBroken("<a><b><c>ttt</c></b>"));
    Assert.assertTrue(AgUtils.isMarkupBroken("<a href=\"test\"><b>ttt</a>"));
    Assert.assertTrue(AgUtils.isMarkupBroken("test <a href=\"test\">"));
    Assert.assertTrue(AgUtils.isMarkupBroken("test <a href=\"te"));
  }