Exemplo n.º 1
0
 /** @param args */
 public static void mainold(String[] args) {
   try {
     LevenshteinDistance distance = new LevenshteinDistance();
     distance.setFirstString("abA");
     distance.setSecondString("bba");
     distance.setCaseSensitive(false);
     System.out.println(distance.computeDistance());
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  private void verifyTargetOperations(
      String[] source, String[] target, int[] expectedOps, int expectedDistance) {

    Token[] sourceTokens = makeTokens(source);
    Token[] targetTokens = makeTokens(target);

    assertEquals("test error", target.length, expectedOps.length);
    LevenshteinDistance distance = new LevenshteinDistance(sourceTokens, targetTokens);

    assertEquals(expectedDistance, distance.calculate());
    EditOperation[] ops = distance.getTargetOperations();
    assertEquals(expectedOps.length, ops.length);
    for (int i = 0; i < ops.length; ++i) {
      assertEquals(
          "Token " + i + " '" + target[i] + "' has wrong operation",
          expectedOps[i],
          ops[i].getType());
      if (expectedOps[i] == UNCHANGED) {
        assertEquals(source[ops[i].getPosition()], target[i]);
      } else if (expectedOps[i] == REPLACE) {
        assertFalse(source[ops[i].getPosition()].equals(target[i]));
      }
    }
  }
 /**
  * Tests the {@code calculate} method with at least one {@code null} string.
  *
  * @param s The source string to compare.
  * @param t The target string to compare.
  */
 @Test(
     dataProvider = "testnulls",
     expectedExceptions = {NullPointerException.class})
 public void testNullStrings(String s, String t) {
   LevenshteinDistance.calculate(s, t);
 }
 /**
  * Tests the {@code calculate} method with non-{@code null} String arguments in reverse order to
  * verify that they are order-independent.
  *
  * @param s The source string to compare.
  * @param t The target string to compare.
  * @param d The expected Levenshtein distance for the two strings.
  */
 @Test(dataProvider = "teststrings")
 public void testCalculateStringsReversed(String s, String t, int d) {
   assertEquals(LevenshteinDistance.calculate(t, s), d);
 }