@Test public void testSimpleDiff() throws Exception { assertDiff("a,b", "a,b,c", asList("c")); assertDiff("a,b", "", Collections.<String> emptyList()); assertDiff("", "", Collections.<String> emptyList()); assertDiff("", "a", asList("a")); assertDiff("", "a, b", asList("a", "b")); }
@Test public void testDiffWithExtraEntriesInMarked() throws IOException { assertDiff("a,b", "a,b,c, e, h", asList("c", "e", "h")); assertDiff("a,b,d,e", "a,b,c", asList("c")); assertDiff("a,b,d,e,f", "a,b,c,f", asList("c")); assertDiff("a,b,d,e,f", "a,b,c,f, h", asList("c", "h")); assertDiff("3,7", "2,3,5,9", asList("2", "5", "9")); }
@Test public void testNoDiff() throws Exception { assertDiff("a,b,c", "a,b,c", Collections.<String> emptyList()); assertDiff("a,b,c,d,f", "a,b,f", Collections.<String> emptyList()); }
@Test public void testDiffLineBreakChars() throws IOException { List<String> all = getLineBreakStrings(); List<String> marked = getLineBreakStrings(); remove(marked, 3, 2); // without escaping, the line breaks will be resolved assertDiff(Joiner.on(",").join(marked), Joiner.on(",").join(all), asList("/a", "c", "/a/b")); }
@Test public void testRandomized() throws Exception { Random r = new Random(0); for (int i = 0; i < 10000; i++) { TreeSet<String> marked = new TreeSet<String>(); TreeSet<String> all = new TreeSet<String>(); TreeSet<String> diff = new TreeSet<String>(); int size = r.nextInt(5); for (int a = 0; a < size; a++) { marked.add("" + r.nextInt(10)); } size = r.nextInt(5); for (int a = 0; a < size; a++) { all.add("" + r.nextInt(10)); } diff.addAll(all); diff.removeAll(marked); String m = marked.toString().replaceAll("[ \\[\\]]", ""); String a = all.toString().replaceAll("[ \\[\\]]", ""); assertDiff(m, a, new ArrayList<String>(diff)); } }
@Test public void testDiffEscapedLineBreakChars() throws IOException { // Escaped characters List<String> all = escape(getLineBreakStrings()); List<String> marked = escape(getLineBreakStrings()); List<String> diff = remove(marked, 3, 2); assertDiff(Joiner.on(",").join(marked), Joiner.on(",").join(all), diff); }