### Question:
WeightedLevenshtein implements Comparator { public static double distance(String s1, String s2, WeightEstimator weight) { int s1len = s1.length(); if (s1len == 0) return estimateCharacters(s2, weight); if (s2.length() == 0) return estimateCharacters(s1, weight); double[] matrix = new double[(s1len + 1) * (s2.length() + 1)]; for (int col = 0; col <= s2.length(); col++) matrix[col * s1len] = col; for (int row = 0; row <= s1len; row++) matrix[row] = row; for (int ix1 = 0; ix1 < s1len; ix1++) { char ch1 = s1.charAt(ix1); for (int ix2 = 0; ix2 < s2.length(); ix2++) { double cost; char ch2 = s2.charAt(ix2); if (ch1 == ch2) cost = 0; else cost = weight.substitute(ix1, ch1, s2.charAt(ix2)); double left = matrix[ix1 + ((ix2 + 1) * s1len)] + weight.delete(ix1, ch1); double above = matrix[ix1 + 1 + (ix2 * s1len)] + weight.insert(ix1, ch2); double aboveleft = matrix[ix1 + (ix2 * s1len)] + cost; matrix[ix1 + 1 + ((ix2 + 1) * s1len)] = Math.min(left, Math.min(above, aboveleft)); } } return matrix[s1len + (s2.length() * s1len)]; } WeightedLevenshtein(); double compare(String s1, String s2); boolean isTokenized(); void setEstimator(WeightEstimator estimator); WeightEstimator getEstimator(); static double distance(String s1, String s2, WeightEstimator weight);  }### Answer:
@Test public void testEmpty() { assertEquals(0.0, WeightedLevenshtein.distance("", "", e)); }
@Test public void testEmpty1() { e.setDigitWeight(1.0); assertEquals(1.0, WeightedLevenshtein.distance("", "1", e)); }
@Test public void testEmpty2() { e.setDigitWeight(2.0); assertEquals(2.0, WeightedLevenshtein.distance("1", "", e)); }
@Test public void testSubstitute1() { e.setDigitWeight(2.0); assertEquals(2.0, WeightedLevenshtein.distance("titanic 1", "titanic 2", e)); }
@Test public void testSubstitute2() { e.setDigitWeight(2.0); assertEquals(3.0, WeightedLevenshtein.distance("totanic 1", "titanic 2", e)); }