diff options
2 files changed, 76 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 00d917ced..4b2c825ed 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 @@ -29,6 +29,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.ConflictMergeTest; import org.eclipse.emf.compare.tests.merge.ExtensionMergeTest; import org.eclipse.emf.compare.tests.merge.IndividualMergeOutOfScopeValuesTest; @@ -58,7 +59,8 @@ import org.junit.runners.Suite.SuiteClasses; PostProcessorTest.class, IndividualMergeTest.class, ExtensionMergeTest.class, IndividualMergeOutOfScopeValuesTest.class, ProximityComparisonTest.class, DynamicInstanceComparisonTest.class, URIDistanceTest.class, FragmentationTest.class, - AllEditTests.class, CommandStackTestSuite.class, MatchEngineFactoryRegistryTest.class, ConflictMergeTest.class }) + AllEditTests.class, CommandStackTestSuite.class, MatchEngineFactoryRegistryTest.class, + ConflictMergeTest.class, ProximityIndexTest.class }) public class AllTests { /** * Standalone launcher for all of compare's tests. |