Strings { public static int shortestUniquePrefix(Collection<String> strings) { return shortestUniquePrefix(strings, 1); }  static int commonPrefixSegments(char separator, Collection<String> strings); static int commonPrefixSegments(char separator, Collection<String> strings, int minSize); static String trimLeadingSegments(String string, char separator, int segmentCount); static int shortestUniquePrefix(Collection<String> strings); static int shortestUniquePrefix(Collection<String> strings, int minSize); static String safeTruncate(String string, int length);  }
@Test public void testShortestUniquePrefix() { assertEquals(shortestUniquePrefix(of("aa", "aaa")), 3); assertEquals(shortestUniquePrefix(of("a")), 1); assertEquals(shortestUniquePrefix(of("aaaaa")), 1); assertEquals(shortestUniquePrefix(of("a", "b", "c")), 1); assertEquals(shortestUniquePrefix(of("axxxxx", "b", "c")), 1); assertEquals(shortestUniquePrefix(of("ax", "bx", "cx")), 1); assertEquals(shortestUniquePrefix(of("ax", "ay", "cx")), 2); assertEquals(shortestUniquePrefix(of("axxx", "ayyyy", "cxxxx")), 2); assertEquals(shortestUniquePrefix(of("aaaax", "aaaay")), 5); assertEquals(shortestUniquePrefix(of("aaaaxx", "aaaayx", "ccc")), 5); assertEquals(shortestUniquePrefix(of("a1", "b2", "b3", "b4", "b5")), 2); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".*unique.*") public void testDuplicateStrings() { shortestUniquePrefix(of("aaa", "aaa")); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".*unique.*") public void testDuplicateStrings2() { shortestUniquePrefix(of("aaa", "aa", "aaa")); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".*unique.*") public void testDuplicateStrings3() { shortestUniquePrefix(of("aa", "aaa", "aa", "aa")); }