Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlgoubet2012-05-22 03:52:16 -0400
committerlgoubet2012-05-22 03:52:16 -0400
commit5cff040a3129c95e16b51737c23fd2d8d10cdada (patch)
tree3247d24d7eedbb3c67b59e7c4bbc7885396edae7 /plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff
parent8a281e33b3573e7d4cdee0f1dd9dce4b9c3fe413 (diff)
downloadorg.eclipse.emf.compare-5cff040a3129c95e16b51737c23fd2d8d10cdada.tar.gz
org.eclipse.emf.compare-5cff040a3129c95e16b51737c23fd2d8d10cdada.tar.xz
org.eclipse.emf.compare-5cff040a3129c95e16b51737c23fd2d8d10cdada.zip
Basic testing of the LCS algorithm
Diffstat (limited to 'plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff')
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffEngineTest.java103
1 files changed, 103 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffEngineTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffEngineTest.java
new file mode 100644
index 000000000..4e639d09d
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffEngineTest.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.diff;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertSame;
+
+import com.google.common.collect.Lists;
+
+import java.util.List;
+
+import org.eclipse.emf.compare.CompareFactory;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.diff.DefaultDiffEngine;
+import org.junit.Test;
+
+/**
+ * We will use this to test the utility methods exposed by the {@link DefaultDiffEngine}.
+ *
+ * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
+ */
+@SuppressWarnings("all")
+public class DiffEngineTest {
+ @Test
+ public void lcsTest1() {
+ final List<Character> left = Lists.charactersOf("abcde");
+ final List<Character> right = Lists.charactersOf("czdab");
+
+ final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
+ final List<Character> lcs = DefaultDiffEngine.longestCommonSubsequence(emptyComparison, left, right);
+
+ /*
+ * This is documented in {@link DefaultDiffEngine#longestCommonSubsequence(Comparison, List, List)}.
+ * Ensure the documentation stays in sync.
+ */
+ assertEqualContents(Lists.charactersOf("cd"), lcs);
+ }
+
+ @Test
+ public void lcsTest2() {
+ final List<Character> left = Lists.charactersOf("abcde");
+ final List<Character> right = Lists.charactersOf("ycdeb");
+
+ final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
+ final List<Character> lcs = DefaultDiffEngine.longestCommonSubsequence(emptyComparison, left, right);
+
+ /*
+ * This is documented in {@link DefaultDiffEngine#longestCommonSubsequence(Comparison, List, List)}.
+ * Ensure the documentation stays in sync.
+ */
+ assertEqualContents(Lists.charactersOf("cde"), lcs);
+ }
+
+ @Test
+ public void lcsTest3() {
+ final List<Integer> left = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7);
+ final List<Integer> right = Lists.newArrayList(8, 9, 2, 3, 4, 1, 0);
+
+ final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
+ final List<Integer> lcs = DefaultDiffEngine.longestCommonSubsequence(emptyComparison, left, right);
+
+ // These are the origin and left sides of the "complex" conflict test case.
+ assertEqualContents(Lists.newArrayList(2, 3, 4), lcs);
+ }
+
+ @Test
+ public void lcsTest4() {
+ final List<Integer> left = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7);
+ final List<Integer> right = Lists.newArrayList(6, 2, 9, 3, 0, 4, 1, 7);
+
+ final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
+ final List<Integer> lcs = DefaultDiffEngine.longestCommonSubsequence(emptyComparison, left, right);
+
+ // These are the origin and right sides of the "complex" conflict test case.
+ assertEqualContents(Lists.newArrayList(2, 3, 4, 7), lcs);
+ }
+
+ /**
+ * Ensures that the two given lists contain the same elements in the same order. The kind of list does not
+ * matter.
+ *
+ * @param list1
+ * First of the two lists to compare.
+ * @param list2
+ * Second of the two lists to compare.
+ */
+ private static <T> void assertEqualContents(List<T> list1, List<T> list2) {
+ final int size = list1.size();
+ assertSame(Integer.valueOf(size), Integer.valueOf(list2.size()));
+
+ for (int i = 0; i < size; i++) {
+ assertEquals(list1.get(i), list2.get(i));
+ }
+ }
+}

Back to the top