Skip to content

Commit d0ac149

Browse files
committed
test: fix the DiffTreeParser tests for non-GumTree matchers
Previously, all tests would run with the default GumTree matcher instead of the matcher stated in the test case file name. As stated in my bachelor thesis, some matchers fail to return a valid matching. Hence, some test cases need to be removed.
1 parent e64418e commit d0ac149

22 files changed

Lines changed: 119 additions & 263 deletions

src/main/java/org/variantsync/diffdetective/variation/diff/construction/GumTreeDiff.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,18 @@ public class GumTreeDiff {
3434
* @see diffUsingMatching(VariationNode, VariationNode, Matcher)
3535
*/
3636
public static <L extends Label> VariationDiff<L> diffUsingMatching(VariationTree<L> before, VariationTree<L> after) {
37+
return diffUsingMatching(before, after, Matchers.getInstance().getMatcher());
38+
}
39+
40+
/**
41+
* Create a {@link VariationDiff} by matching nodes between {@code before} and {@code after}
42+
* with {@code matcher}.
43+
*/
44+
public static <L extends Label> VariationDiff<L> diffUsingMatching(VariationTree<L> before, VariationTree<L> after, Matcher matcher) {
3745
DiffNode<L> root = diffUsingMatching(
3846
before.root(),
3947
after.root(),
40-
Matchers.getInstance().getMatcher()
48+
matcher
4149
);
4250

4351
return new VariationDiff<>(root, new VariationTreeDiffSource(before.source(), after.source()));
@@ -84,7 +92,18 @@ public static <B extends VariationNode<B, L>, L extends Label> DiffNode<L> diffU
8492
var dst = new VariationTreeAdapter<L>(after);
8593

8694
MappingStore matching = matcher.match(src, dst);
87-
Assert.assertTrue(matching.has(src, dst));
95+
96+
// We assume that the root nodes are matched.
97+
if (!matching.has(src, dst)) {
98+
if (matching.isSrcMapped(src)) {
99+
matching.removeMapping(src, matching.getDstForSrc(src));
100+
}
101+
if (matching.isDstMapped(dst)) {
102+
matching.removeMapping(dst, matching.getSrcForDst(dst));
103+
}
104+
105+
matching.addMapping(src, dst);
106+
}
88107

89108
removeUnmapped(matching, src);
90109
for (var child : dst.getChildren()) {

src/test/java/TreeDiffingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void testCase(TestCase testCase) throws IOException, DiffParseException {
7979
VariationTree<DiffLinesLabel> beforeEdit = parseVariationTree(testCase.beforeEdit());
8080
VariationTree<DiffLinesLabel> afterEdit = parseVariationTree(testCase.afterEdit());
8181

82-
VariationDiff<DiffLinesLabel> variationDiff = GumTreeDiff.diffUsingMatching(beforeEdit, afterEdit);
82+
VariationDiff<DiffLinesLabel> variationDiff = GumTreeDiff.diffUsingMatching(beforeEdit, afterEdit, testCase.matcher());
8383

8484
try (var output = IO.newBufferedOutputStream(testCase.actual())) {
8585
new LineGraphExporter<>(new Format<>(new FullNodeFormat(), new ChildOrderEdgeFormat<>()))

src/test/resources/tree-diffing/07_gumtree-hybrid-id_expected.lg

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/test/resources/tree-diffing/07_gumtree-partition-id_expected.lg

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/test/resources/tree-diffing/07_gumtree-simple-id-theta_expected.lg

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/test/resources/tree-diffing/07_gumtree-simple-id_expected.lg

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
v 80 NON;IF;(old: -1, diff: 0, new: -1);(old: -1, diff: 0, new: -1);True
2-
v 136 REM;IF;(old: 1, diff: 1, new: -1);(old: 5, diff: 1, new: -1);defined(CONFIG_A);#ifdef CONFIG_A
2+
v 144 NON;IF;(old: 1, diff: 1, new: 1);(old: 5, diff: 1, new: 5);defined(CONFIG_A);#ifdef CONFIG_A
33
v 200 REM;IF;(old: 2, diff: 2, new: -1);(old: 4, diff: 2, new: -1);defined(CONFIG_B);#ifdef CONFIG_B
44
v 275 NON;ARTIFACT;(old: 3, diff: 3, new: 3);(old: 4, diff: 3, new: 4);;Line
55
v 320 ADD;IF;(old: -1, diff: 4, new: 1);(old: -1, diff: 4, new: 5);defined(CONFIG_B);#ifdef CONFIG_B
6-
v 384 ADD;IF;(old: -1, diff: 5, new: 2);(old: -1, diff: 5, new: 4);defined(CONFIG_A);#ifdef CONFIG_A
7-
e 136 80 b;0,-1
6+
e 144 80 b;0,-1
87
e 320 80 a;-1,0
9-
e 200 136 b;0,-1
8+
e 200 144 b;0,-1
9+
e 275 144 a;-1,0
1010
e 275 200 b;0,-1
11-
e 384 320 a;-1,0
12-
e 275 384 a;-1,0
11+
e 144 320 a;-1,0
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
v 80 NON;IF;(old: -1, diff: 0, new: -1);(old: -1, diff: 0, new: -1);True
22
v 136 REM;IF;(old: 1, diff: 1, new: -1);(old: 5, diff: 1, new: -1);defined(CONFIG_A);#ifdef CONFIG_A
33
v 200 REM;IF;(old: 2, diff: 2, new: -1);(old: 4, diff: 2, new: -1);defined(CONFIG_B);#ifdef CONFIG_B
4-
v 275 NON;ARTIFACT;(old: 3, diff: 3, new: 3);(old: 4, diff: 3, new: 4);;Line
4+
v 267 REM;ARTIFACT;(old: 3, diff: 3, new: -1);(old: 4, diff: 3, new: -1);;Line
55
v 320 ADD;IF;(old: -1, diff: 4, new: 1);(old: -1, diff: 4, new: 5);defined(CONFIG_B);#ifdef CONFIG_B
66
v 384 ADD;IF;(old: -1, diff: 5, new: 2);(old: -1, diff: 5, new: 4);defined(CONFIG_A);#ifdef CONFIG_A
7+
v 451 ADD;ARTIFACT;(old: -1, diff: 6, new: 3);(old: -1, diff: 6, new: 4);;Line
78
e 136 80 b;0,-1
89
e 320 80 a;-1,0
910
e 200 136 b;0,-1
10-
e 275 200 b;0,-1
11+
e 267 200 b;0,-1
1112
e 384 320 a;-1,0
12-
e 275 384 a;-1,0
13+
e 451 384 a;-1,0

src/test/resources/tree-diffing/08_gumtree-hybrid-id_expected.lg

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/test/resources/tree-diffing/08_gumtree-partition-id_expected.lg

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)