### Question:
FeatureBasedSimilarity extends AbstractStringMetric { @Override public double getSimilarity(String s1, String s2) { Validate.notNull(s1, "s1 must not be null"); Validate.notNull(s2, "s2 must not be null"); if (s1.equals(s2)) { return 1; } Set<String> features1 = extractFeatures(s1); Set<String> features2 = extractFeatures(s2); return setSimilarity.getSimilarity(features1, features2); } FeatureBasedSimilarity(FeatureSetting featureSetting, SetSimilarity setSimilarity); @Override double getSimilarity(String s1, String s2); @Override String toString();  }### Answer:
@Test public void testNGramSimilarity() { StringMetric similarity = new FeatureBasedSimilarity(chars(3).characterPadding().create(), DICE); assertEquals(1.0, similarity.getSimilarity("", ""), DELTA); assertEquals(0.0, similarity.getSimilarity("", "string"), DELTA); assertEquals(1.0, similarity.getSimilarity("a", "a"), DELTA); assertEquals(1.0, similarity.getSimilarity("cat", "cat"), DELTA); assertEquals(0.727, similarity.getSimilarity("cat", "caat"), DELTA); assertEquals(0.0, similarity.getSimilarity("cat", "dog"), DELTA); assertEquals(0.824, similarity.getSimilarity("philipp", "philip"), DELTA); assertEquals(0.333, similarity.getSimilarity("philipp", "p"), DELTA); assertEquals(0.5, similarity.getSimilarity("word", "wort"), DELTA); }
@Test public void testNGramSimilarityJaccard() { StringMetric similarity = new FeatureBasedSimilarity(chars(3).characterPadding().create(), JACCARD); assertEquals(1.0, similarity.getSimilarity("", ""), DELTA); assertEquals(0.0, similarity.getSimilarity("", "string"), DELTA); assertEquals(1.0, similarity.getSimilarity("a", "a"), DELTA); assertEquals(1.0, similarity.getSimilarity("cat", "cat"), DELTA); assertEquals(0.571, similarity.getSimilarity("cat", "caat"), DELTA); assertEquals(0.0, similarity.getSimilarity("cat", "dog"), DELTA); assertEquals(0.7, similarity.getSimilarity("philipp", "philip"), DELTA); assertEquals(0.2, similarity.getSimilarity("philipp", "p"), DELTA); assertEquals(0.333, similarity.getSimilarity("word", "wort"), DELTA); }
@Test public void testNGramSimilarityOverlap() { StringMetric similarity = new FeatureBasedSimilarity(chars(3).characterPadding().create(), OVERLAP); assertEquals(1.0, similarity.getSimilarity("", ""), DELTA); assertEquals(0.0, similarity.getSimilarity("", "string"), DELTA); assertEquals(1.0, similarity.getSimilarity("a", "a"), DELTA); assertEquals(1.0, similarity.getSimilarity("cat", "cat"), DELTA); assertEquals(0.8, similarity.getSimilarity("cat", "caat"), DELTA); assertEquals(0.0, similarity.getSimilarity("cat", "dog"), DELTA); assertEquals(0.875, similarity.getSimilarity("philipp", "philip"), DELTA); assertEquals(0.666, similarity.getSimilarity("philipp", "p"), DELTA); assertEquals(0.5, similarity.getSimilarity("word", "wort"), DELTA); }