Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlgoubet2012-09-17 11:09:30 -0400
committerlgoubet2012-09-17 11:09:30 -0400
commit7ffdcd1d74d573e3b5ac095f101a8322ff6cabb4 (patch)
treee7ac8af7072195be9ba02cb69ab1439dbc5a53bd /plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff
parent10d37226d1e8c6dbebf514c3fc7b73c5e5078c01 (diff)
downloadorg.eclipse.emf.compare-7ffdcd1d74d573e3b5ac095f101a8322ff6cabb4.tar.gz
org.eclipse.emf.compare-7ffdcd1d74d573e3b5ac095f101a8322ff6cabb4.tar.xz
org.eclipse.emf.compare-7ffdcd1d74d573e3b5ac095f101a8322ff6cabb4.zip
Adding tests for the Dice Coefficient
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/DiffUtilTest.java116
1 files changed, 116 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java
index f1edebba2..a270b0936 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java
@@ -12,6 +12,7 @@ package org.eclipse.emf.compare.tests.diff;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertSame;
+import static junit.framework.Assert.fail;
import com.google.common.collect.Lists;
@@ -368,6 +369,121 @@ public class DiffUtilTest {
}
/**
+ * Tests {@link NameSimilarity#nameSimilarityMetric(String, String)}.
+ * <p>
+ * Expected results :
+ * <table>
+ * <tr>
+ * <td>arg1</td>
+ * <td>arg2</td>
+ * <td>result</td>
+ * </tr>
+ * <tr>
+ * <td>&quot;ceString&quot;</td>
+ * <td>&quot;ceString&quot;</td>
+ * <td><code>1</code></td>
+ * </tr>
+ * <tr>
+ * <td>&quot;classe&quot;</td>
+ * <td>&quot;Classe&quot;</td>
+ * <td><code>0.8</code></td>
+ * </tr>
+ * <tr>
+ * <td>&quot;Classe&quot;</td>
+ * <td>&quot;UneClasse&quot;</td>
+ * <td><code>10/13</code></td>
+ * </tr>
+ * <tr>
+ * <td>&quot;package&quot;</td>
+ * <td>&quot;packagedeux&quot;</td>
+ * <td><code>12/16</code></td>
+ * </tr>
+ * <tr>
+ * <td>&quot;&quot;</td>
+ * <td>&quot;MaClasse&quot;</td>
+ * <td><code>0</code></td>
+ * </tr>
+ * <tr>
+ * <td>&quot;package&quot;</td>
+ * <td>&quot;packageASupprimer&quot;</td>
+ * <td><code>12/22</code></td>
+ * </tr>
+ * <tr>
+ * <td>&quot;attribut&quot;</td>
+ * <td>&quot;reference&quot;</td>
+ * <td><code>0</code></td>
+ * </tr>
+ * <tr>
+ * <td>&quot;aa&quot;</td>
+ * <td>&quot;aaaa&quot;</td>
+ * <td><code>1/3</code></td>
+ * </tr>
+ * <tr>
+ * <td>&quot;v1&quot;</td>
+ * <td>&quot;v2&quot;</td>
+ * <td><code>2/4</code></td>
+ * </tr>
+ * <tr>
+ * <td>&quot;v&quot;</td>
+ * <td>&quot;v1&quot;</td>
+ * <td><code>1/3</code></td>
+ * </tr>
+ * <tr>
+ * <td>&quot;a&quot;</td>
+ * <td>&quot;a&quot;</td>
+ * <td><code>1</code></td>
+ * </tr>
+ * <tr>
+ * <td>&quot;a&quot;</td>
+ * <td>&quot;b&quot;</td>
+ * <td><code>0</code></td>
+ * </tr>
+ * <tr>
+ * <td>&quot;a&quot;</td>
+ * <td>&quot;A&quot;</td>
+ * <td><code>0</code></td>
+ * </tr>
+ * </table>
+ * </p>
+ */
+ @Test
+ public void diceCoefficient() {
+ final String[] data = new String[] {"ceString", "ceString", "classe", "Classe", "Classe",
+ "UneClasse", "package", "packagedeux", "", "MaClasse", "package", "packageASupprimer",
+ "attribut", "reference", "aa", "aaaa", "v1", "v2", "v", "v1", "a", "a", "a", "b", "a", "A" };
+ final double[] similarities = new double[] {1d, 0.8d, 10d / 13d, 3d / 4d, 0d, 6d / 11d, 0d, 1d / 3d,
+ 1d / 2d, 1d / 3d, 1d, 0d, 0d, };
+ for (int i = 0; i < data.length; i += 2) {
+ assertEquals("Unexpected result of the dice coefficient for str1 = " + data[i] + " and str2 = "
+ + data[i + 1], similarities[i / 2], DiffUtil.diceCoefficient(data[i], data[i + 1]));
+ // Make sure that the result is symmetric
+ assertEquals("Dice coefficient was not symmetric for str1 = " + data[i] + " and str2 = "
+ + data[i + 1], similarities[i / 2], DiffUtil.diceCoefficient(data[i + 1], data[i]));
+ }
+ }
+
+ public void diceCoefficientFailure() {
+ try {
+ DiffUtil.diceCoefficient(null, null);
+ fail("Expected exception has not been thrown");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ try {
+ DiffUtil.diceCoefficient(null, "aString");
+ fail("Expected exception has not been thrown");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ try {
+ DiffUtil.diceCoefficient("aString", null);
+ fail("Expected exception has not been thrown");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ /**
* Ensures that the two given lists contain the same elements in the same order. The kind of list does not
* matter.
*

Back to the top