You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ki...@apache.org on 2015/02/11 01:16:03 UTC
[text] Add tests for longest common subsequence
Repository: commons-text
Updated Branches:
refs/heads/myers-algo f3cff64cc -> 300b82630
Add tests for longest common subsequence
Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/300b8263
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/300b8263
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/300b8263
Branch: refs/heads/myers-algo
Commit: 300b82630789255ae3f443bce9102add247908b7
Parents: f3cff64
Author: Bruno P. Kinoshita <ki...@apache.org>
Authored: Tue Feb 10 22:15:54 2015 -0200
Committer: Bruno P. Kinoshita <ki...@apache.org>
Committed: Tue Feb 10 22:15:54 2015 -0200
----------------------------------------------------------------------
.../text/diff/StringsComparatorTest.java | 40 ++++++++++----------
1 file changed, 19 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-text/blob/300b8263/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java b/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java
index 02b77be..d5d7690 100644
--- a/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java
+++ b/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java
@@ -15,24 +15,20 @@
* limitations under the License.
*/
package org.apache.commons.text.diff;
-
import java.util.Arrays;
import java.util.List;
-
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-
/**
* Tests for the StringsComparator.
*/
public class StringsComparatorTest {
-
private List<String> before;
private List<String> after;
private int[] length;
-
+ private int[] lcs;
@Test
public void testLength() {
for (int i = 0; i < before.size(); ++i) {
@@ -40,7 +36,13 @@ public class StringsComparatorTest {
Assert.assertEquals(length[i], comparator.getScript().getModifications());
}
}
-
+ @Test
+ public void testLongestCommonSubsequence() {
+ for (int i = 0; i < before.size(); ++i) {
+ final StringsComparator comparator = new StringsComparator(before.get(i), after.get(i));
+ Assert.assertEquals(lcs[i], comparator.getScript().getLCSLength());
+ }
+ }
@Test
public void testExecution() {
for (int i = 0; i < before.size(); ++i) {
@@ -49,35 +51,25 @@ public class StringsComparatorTest {
Assert.assertEquals(after.get(i), ev.getString());
}
}
-
private class ExecutionVisitor<T> implements CommandVisitor<T> {
-
private StringBuilder v;
-
public ExecutionVisitor() {
v = new StringBuilder();
}
-
public void visitInsertCommand(final T object) {
v.append(object);
}
-
public void visitKeepCommand(final T object) {
v.append(object);
}
-
public void visitDeleteCommand(final T object) {
}
-
public String getString() {
return v.toString();
}
-
}
-
@Before
public void setUp() {
-
before = Arrays.asList(
"bottle",
"nematode knowledge",
@@ -88,7 +80,6 @@ public class StringsComparatorTest {
"glop glop",
"coq",
"spider-man");
-
after = Arrays.asList(
"noodle",
"empty bottle",
@@ -99,7 +90,6 @@ public class StringsComparatorTest {
"pas glop pas glop",
"ane",
"klingon");
-
length = new int[] {
6,
16,
@@ -111,14 +101,22 @@ public class StringsComparatorTest {
6,
13
};
-
+ lcs = new int[] {
+ 3,
+ 7,
+ 0,
+ 0,
+ 6,
+ 4,
+ 9,
+ 0,
+ 2
+ };
}
-
@After
public void tearDown() {
before = null;
after = null;
length = null;
}
-
}