Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbrun2013-12-19 15:10:01 -0500
committerLaurent Goubet2014-02-03 09:35:13 -0500
commit6b8a61f0ae4a47651aeadb5c0106e08ae6324cd8 (patch)
treed66aacbcbbb3638f32d7ba50a9927fd28dc508c6
parentd124b61dce551ef44498a1b58f4eab396b116db7 (diff)
downloadorg.eclipse.emf.compare-6b8a61f0ae4a47651aeadb5c0106e08ae6324cd8.tar.gz
org.eclipse.emf.compare-6b8a61f0ae4a47651aeadb5c0106e08ae6324cd8.tar.xz
org.eclipse.emf.compare-6b8a61f0ae4a47651aeadb5c0106e08ae6324cd8.zip
[421609] ProximityEObjectMatcher match even when Distance function sais no
Introduce a test to make sure the Proximity index will never return a "closest" EObject if it uses a distance which always return the MAX. Change-Id: I279c21dab920b75d312fbf41528dcc40f1d8cdfc Conflicts: plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/ProximityIndexTest.java73
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java3
2 files changed, 75 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/ProximityIndexTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/ProximityIndexTest.java
new file mode 100644
index 000000000..8fcebb08b
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/ProximityIndexTest.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.match;
+
+import static org.junit.Assert.assertNull;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.compare.CompareFactory;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.match.eobject.EObjectIndex.Side;
+import org.eclipse.emf.compare.match.eobject.ProximityEObjectMatcher.DistanceFunction;
+import org.eclipse.emf.compare.match.eobject.ScopeQuery;
+import org.eclipse.emf.compare.match.eobject.internal.ProximityIndex;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.junit.Test;
+
+/**
+ * A few tests to validate the behavior of the ProximityIndex.
+ *
+ * @author <a href="mailto:cedric.brun@obeo.fr">Cedric Brun</a>
+ */
+public class ProximityIndexTest {
+
+ @Test
+ public void neverMatchWhenDistanceIsMax() throws Exception {
+ DistanceFunction notAChance = new DistanceFunction() {
+
+ public double distance(Comparison inProgress, EObject a, EObject b) {
+ return Double.MAX_VALUE;
+ }
+
+ public boolean areIdentic(Comparison inProgress, EObject a, EObject b) {
+ return false;
+ }
+ };
+ ScopeQuery alwaysIn = new ScopeQuery() {
+
+ public boolean isInScope(EObject any) {
+ return true;
+ }
+ };
+ ProximityIndex index = new ProximityIndex(notAChance, alwaysIn);
+ fillIndex(index, Side.LEFT, EcoreUtil.copy(EcorePackage.eINSTANCE));
+ fillIndex(index, Side.RIGHT, EcoreUtil.copy(EcorePackage.eINSTANCE));
+
+ Comparison comp = CompareFactory.eINSTANCE.createComparison();
+ for (EObject leftElement : index.getValuesStillThere(Side.LEFT)) {
+ assertNull(
+ "With a distance which always return Double.MAX_VALUE we should never find a closest.",
+ index.findClosests(comp, leftElement, Side.LEFT));
+ }
+
+ }
+
+ private void fillIndex(ProximityIndex index, Side side, EObject model) {
+ Iterator<EObject> it = model.eAllContents();
+ while (it.hasNext()) {
+ EObject eObj = it.next();
+ index.index(eObj, side);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
index c9377fa13..1dc6e05ed 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
@@ -28,6 +28,7 @@ import org.eclipse.emf.compare.tests.fullcomparison.ExtLibraryTest;
import org.eclipse.emf.compare.tests.fullcomparison.IdentifierComparisonTest;
import org.eclipse.emf.compare.tests.fullcomparison.ProximityComparisonTest;
import org.eclipse.emf.compare.tests.match.MatchEngineFactoryRegistryTest;
+import org.eclipse.emf.compare.tests.match.ProximityIndexTest;
import org.eclipse.emf.compare.tests.merge.ExtensionMergeTest;
import org.eclipse.emf.compare.tests.merge.IndividualMergeOutOfScopeValuesTest;
import org.eclipse.emf.compare.tests.merge.IndividualMergeTest;
@@ -56,7 +57,7 @@ import org.junit.runners.Suite.SuiteClasses;
IndividualMergeTest.class, ExtensionMergeTest.class, IndividualMergeOutOfScopeValuesTest.class,
ProximityComparisonTest.class, DynamicInstanceComparisonTest.class, URIDistanceTest.class,
FragmentationTest.class, AllEditTests.class, CommandStackTestSuite.class,
- MatchEngineFactoryRegistryTest.class })
+ MatchEngineFactoryRegistryTest.class, ProximityIndexTest.class })
public class AllTests {
/**
* Standalone launcher for all of compare's tests.

Back to the top