1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.diff;
45
46 import static org.junit.Assert.assertEquals;
47
48 import org.junit.Test;
49
50
51 public class HistogramDiffTest extends AbstractDiffTestCase {
52 @Override
53 protected HistogramDiff algorithm() {
54 HistogramDiff hd = new HistogramDiff();
55 hd.setFallbackAlgorithm(null);
56 return hd;
57 }
58
59 @Test
60 public void testEdit_NoUniqueMiddleSide_FlipBlocks() {
61 EditList r = diff(t("aRRSSz"), t("aSSRRz"));
62 assertEquals(2, r.size());
63 assertEquals(new Edit(1, 3, 1, 1), r.get(0));
64 assertEquals(new Edit(5, 5, 3, 5), r.get(1));
65 }
66
67 @Test
68 public void testEdit_NoUniqueMiddleSide_Insert2() {
69 EditList r = diff(t("aRSz"), t("aRRSSz"));
70 assertEquals(1, r.size());
71 assertEquals(new Edit(2, 2, 2, 4), r.get(0));
72 }
73
74 @Test
75 public void testEdit_NoUniqueMiddleSide_FlipAndExpand() {
76 EditList r = diff(t("aRSz"), t("aSSRRz"));
77 assertEquals(2, r.size());
78 assertEquals(new Edit(1, 2, 1, 1), r.get(0));
79 assertEquals(new Edit(3, 3, 2, 5), r.get(1));
80 }
81
82 @Test
83 public void testEdit_LcsContainsUnique() {
84 EditList r = diff(t("nqnjrnjsnm"), t("AnqnjrnjsnjTnmZ"));
85 assertEquals(new Edit(0, 0, 0, 1), r.get(0));
86 assertEquals(new Edit(9, 9, 10, 13), r.get(1));
87 assertEquals(new Edit(10, 10, 14, 15), r.get(2));
88 assertEquals(3, r.size());
89 }
90
91 @Test
92 public void testExceedsChainLength_DuringScanOfA() {
93 HistogramDiff hd = new HistogramDiff();
94 hd.setFallbackAlgorithm(null);
95 hd.setMaxChainLength(3);
96
97 SequenceComparator<RawText> cmp = new SequenceComparator<RawText>() {
98 @Override
99 public boolean equals(RawText a, int ai, RawText b, int bi) {
100 return RawTextComparator.DEFAULT.equals(a, ai, b, bi);
101 }
102
103 @Override
104 public int hash(RawText a, int ai) {
105 return 1;
106 }
107 };
108
109 EditList r = hd.diff(cmp, t("RabS"), t("QabT"));
110 assertEquals(1, r.size());
111 assertEquals(new Edit(0, 4, 0, 4), r.get(0));
112 }
113
114 @Test
115 public void testExceedsChainLength_DuringScanOfB() {
116 HistogramDiff hd = new HistogramDiff();
117 hd.setFallbackAlgorithm(null);
118 hd.setMaxChainLength(1);
119
120 EditList r = hd.diff(RawTextComparator.DEFAULT, t("RaaS"), t("QaaT"));
121 assertEquals(1, r.size());
122 assertEquals(new Edit(0, 4, 0, 4), r.get(0));
123 }
124
125 @Test
126 public void testFallbackToMyersDiff() {
127 HistogramDiff hd = new HistogramDiff();
128 hd.setMaxChainLength(4);
129
130 RawTextComparator cmp = RawTextComparator.DEFAULT;
131 RawText ac = t("bbbbb");
132 RawText bc = t("AbCbDbEFbZ");
133 EditList r;
134
135
136 hd.setFallbackAlgorithm(null);
137 r = hd.diff(cmp, ac, bc);
138 assertEquals(1, r.size());
139
140
141 hd.setFallbackAlgorithm(MyersDiff.INSTANCE);
142 r = hd.diff(cmp, ac, bc);
143 assertEquals(5, r.size());
144 }
145 }