Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2294c5b

Browse files
committed
implemented multi algorithm patch test
1 parent7203d48 commit2294c5b

File tree

4 files changed

+185
-15
lines changed

4 files changed

+185
-15
lines changed

‎java-diff-utils/src/main/java/com/github/difflib/algorithm/myers/MeyersDiffWithLinearSpace.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
packagecom.github.difflib.algorithm.myers;
1717

1818
importcom.github.difflib.algorithm.Change;
19+
importcom.github.difflib.algorithm.DiffAlgorithmFactory;
1920
importcom.github.difflib.algorithm.DiffAlgorithmI;
2021
importcom.github.difflib.algorithm.DiffAlgorithmListener;
2122
importcom.github.difflib.patch.DeltaType;
@@ -221,4 +222,23 @@ public Snake(final int start, final int end, final int diag) {
221222
this.diag =diag;
222223
}
223224
}
225+
226+
/**
227+
* Factory to create instances of this specific diff algorithm.
228+
*/
229+
publicstaticDiffAlgorithmFactoryfactory() {
230+
returnnewDiffAlgorithmFactory() {
231+
@Override
232+
public <T>DiffAlgorithmI<T>
233+
create() {
234+
returnnewMeyersDiffWithLinearSpace<T>();
235+
}
236+
237+
@Override
238+
public <T>DiffAlgorithmI<T>
239+
create(BiPredicate <T,T >equalizer) {
240+
returnnewMeyersDiffWithLinearSpace<T>(equalizer);
241+
}
242+
};
243+
}
224244
}

‎java-diff-utils/src/test/java/com/github/difflib/patch/PatchTest.java‎renamed to ‎java-diff-utils/src/test/java/com/github/difflib/patch/PatchWithAllDiffAlgorithmsTest.java‎

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,35 @@
1111
importjava.util.Arrays;
1212
importjava.util.List;
1313

14-
importorg.junit.jupiter.api.Test;
1514

1615
importcom.github.difflib.DiffUtils;
16+
importcom.github.difflib.algorithm.DiffAlgorithmFactory;
17+
importcom.github.difflib.algorithm.myers.MeyersDiff;
18+
importcom.github.difflib.algorithm.myers.MeyersDiffWithLinearSpace;
19+
importjava.util.stream.Stream;
20+
importorg.junit.jupiter.api.AfterAll;
21+
importorg.junit.jupiter.params.ParameterizedTest;
22+
importorg.junit.jupiter.params.provider.Arguments;
23+
importorg.junit.jupiter.params.provider.MethodSource;
24+
25+
publicclassPatchWithAllDiffAlgorithmsTest {
26+
27+
privatestaticStream<Arguments>provideAlgorithms() {
28+
returnStream.of(
29+
Arguments.of(MeyersDiff.factory()),
30+
Arguments.of(MeyersDiffWithLinearSpace.factory()));
31+
}
32+
33+
@AfterAll
34+
publicstaticvoidafterAll() {
35+
DiffUtils.withDefaultDiffAlgorithmFactory(MeyersDiff.factory());
36+
}
1737

18-
publicclassPatchTest {
19-
20-
@Test
21-
publicvoidtestPatch_Insert() {
38+
@ParameterizedTest
39+
@MethodSource("provideAlgorithms")
40+
publicvoidtestPatch_Insert(DiffAlgorithmFactoryfactory) {
41+
DiffUtils.withDefaultDiffAlgorithmFactory(factory);
42+
2243
finalList<String>insertTest_from =Arrays.asList("hhh");
2344
finalList<String>insertTest_to =Arrays.asList("hhh","jjj","kkk","lll");
2445

@@ -30,8 +51,11 @@ public void testPatch_Insert() {
3051
}
3152
}
3253

33-
@Test
34-
publicvoidtestPatch_Delete() {
54+
@ParameterizedTest
55+
@MethodSource("provideAlgorithms")
56+
publicvoidtestPatch_Delete(DiffAlgorithmFactoryfactory) {
57+
DiffUtils.withDefaultDiffAlgorithmFactory(factory);
58+
3559
finalList<String>deleteTest_from =Arrays.asList("ddd","fff","ggg","hhh");
3660
finalList<String>deleteTest_to =Arrays.asList("ggg");
3761

@@ -43,8 +67,11 @@ public void testPatch_Delete() {
4367
}
4468
}
4569

46-
@Test
47-
publicvoidtestPatch_Change() {
70+
@ParameterizedTest
71+
@MethodSource("provideAlgorithms")
72+
publicvoidtestPatch_Change(DiffAlgorithmFactoryfactory) {
73+
DiffUtils.withDefaultDiffAlgorithmFactory(factory);
74+
4875
finalList<String>changeTest_from =Arrays.asList("aaa","bbb","ccc","ddd");
4976
finalList<String>changeTest_to =Arrays.asList("aaa","bxb","cxc","ddd");
5077

@@ -56,8 +83,11 @@ public void testPatch_Change() {
5683
}
5784
}
5885

59-
@Test
60-
publicvoidtestPatch_Serializable()throwsIOException,ClassNotFoundException {
86+
@ParameterizedTest
87+
@MethodSource("provideAlgorithms")
88+
publicvoidtestPatch_Serializable(DiffAlgorithmFactoryfactory)throwsIOException,ClassNotFoundException {
89+
DiffUtils.withDefaultDiffAlgorithmFactory(factory);
90+
6191
finalList<String>changeTest_from =Arrays.asList("aaa","bbb","ccc","ddd");
6292
finalList<String>changeTest_to =Arrays.asList("aaa","bxb","cxc","ddd");
6393

@@ -79,8 +109,11 @@ public void testPatch_Serializable() throws IOException, ClassNotFoundException
79109

80110
}
81111

82-
@Test
83-
publicvoidtestPatch_Change_withExceptionProcessor() {
112+
@ParameterizedTest
113+
@MethodSource("provideAlgorithms")
114+
publicvoidtestPatch_Change_withExceptionProcessor(DiffAlgorithmFactoryfactory) {
115+
DiffUtils.withDefaultDiffAlgorithmFactory(factory);
116+
84117
finalList<String>changeTest_from =Arrays.asList("aaa","bbb","ccc","ddd");
85118
finalList<String>changeTest_to =Arrays.asList("aaa","bxb","cxc","ddd");
86119

@@ -93,9 +126,9 @@ public void testPatch_Change_withExceptionProcessor() {
93126
try {
94127
List<String>data =DiffUtils.patch(changeTest_from,patch);
95128
assertEquals(9,data.size());
96-
129+
97130
assertEquals(Arrays.asList("aaa","<<<<<< HEAD","bbb","CDC","======","bbb","ccc",">>>>>>> PATCH","ddd"),data);
98-
131+
99132
}catch (PatchFailedExceptione) {
100133
fail(e.getMessage());
101134
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2021 java-diff-utils.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
packagecom.github.difflib.patch;
17+
18+
importcom.github.difflib.DiffUtils;
19+
importjava.util.Arrays;
20+
importjava.util.List;
21+
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
22+
importstaticorg.junit.jupiter.api.Assertions.fail;
23+
importorg.junit.jupiter.api.Test;
24+
25+
/**
26+
*
27+
* @author tw
28+
*/
29+
publicclassPatchWithMeyerDiffTest {
30+
@Test
31+
publicvoidtestPatch_Change_withExceptionProcessor() {
32+
finalList<String>changeTest_from =Arrays.asList("aaa","bbb","ccc","ddd");
33+
finalList<String>changeTest_to =Arrays.asList("aaa","bxb","cxc","ddd");
34+
35+
finalPatch<String>patch =DiffUtils.diff(changeTest_from,changeTest_to);
36+
37+
changeTest_from.set(2,"CDC");
38+
39+
patch.withConflictOutput(Patch.CONFLICT_PRODUCES_MERGE_CONFLICT);
40+
41+
try {
42+
List<String>data =DiffUtils.patch(changeTest_from,patch);
43+
assertEquals(9,data.size());
44+
45+
assertEquals(Arrays.asList("aaa","<<<<<< HEAD","bbb","CDC","======","bbb","ccc",">>>>>>> PATCH","ddd"),data);
46+
47+
}catch (PatchFailedExceptione) {
48+
fail(e.getMessage());
49+
}
50+
}
51+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2021 java-diff-utils.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
packagecom.github.difflib.patch;
17+
18+
importcom.github.difflib.DiffUtils;
19+
importcom.github.difflib.algorithm.myers.MeyersDiff;
20+
importcom.github.difflib.algorithm.myers.MeyersDiffWithLinearSpace;
21+
importjava.util.Arrays;
22+
importjava.util.List;
23+
importorg.junit.jupiter.api.AfterAll;
24+
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
25+
importstaticorg.junit.jupiter.api.Assertions.fail;
26+
importorg.junit.jupiter.api.BeforeAll;
27+
importorg.junit.jupiter.api.Test;
28+
29+
/**
30+
*
31+
* @author tw
32+
*/
33+
publicclassPatchWithMeyerDiffWithLinearSpaceTest {
34+
35+
@BeforeAll
36+
publicstaticvoidsetupClass() {
37+
DiffUtils.withDefaultDiffAlgorithmFactory(MeyersDiffWithLinearSpace.factory());
38+
}
39+
40+
@AfterAll
41+
publicstaticvoidresetClass() {
42+
DiffUtils.withDefaultDiffAlgorithmFactory(MeyersDiff.factory());
43+
}
44+
45+
@Test
46+
publicvoidtestPatch_Change_withExceptionProcessor() {
47+
finalList<String>changeTest_from =Arrays.asList("aaa","bbb","ccc","ddd");
48+
finalList<String>changeTest_to =Arrays.asList("aaa","bxb","cxc","ddd");
49+
50+
finalPatch<String>patch =DiffUtils.diff(changeTest_from,changeTest_to);
51+
52+
changeTest_from.set(2,"CDC");
53+
54+
patch.withConflictOutput(Patch.CONFLICT_PRODUCES_MERGE_CONFLICT);
55+
56+
try {
57+
List<String>data =DiffUtils.patch(changeTest_from,patch);
58+
assertEquals(11,data.size());
59+
60+
assertEquals(Arrays.asList("aaa","bxb","cxc","<<<<<< HEAD","bbb","CDC","======","bbb","ccc",">>>>>>> PATCH","ddd"),data);
61+
62+
}catch (PatchFailedExceptione) {
63+
fail(e.getMessage());
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp