JAL-2106 corrections to DBRefEntry.isPrimary code and tests
[jalview.git] / test / jalview / datamodel / DBRefEntryTest.java
index 09d9df1..ee0bd41 100644 (file)
@@ -144,12 +144,37 @@ public class DBRefEntryTest
   {
     DBRefEntry dbr = new DBRefEntry(DBRefSource.UNIPROT, "", "Q12345");
     assertTrue(dbr.isPrimary());
+
     /*
-     *  1:1 mapping 
+     *  1:1 mapping - ok
      */
     dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 1, 3 }, 1,
             1));
     assertTrue(dbr.isPrimary());
+
+    /*
+     *  1:1 mapping of identical split ranges - not ok
+     */
+    dbr.setMap(new Mapping(null, new int[] { 1, 3, 6, 9 }, new int[] { 1,
+        3, 6, 9 }, 1, 1));
+    assertFalse(dbr.isPrimary());
+
+    /*
+     *  1:1 mapping of different ranges - not ok
+     */
+    dbr.setMap(new Mapping(null, new int[] { 1, 4 }, new int[] { 2, 5 }, 1,
+            1));
+    assertFalse(dbr.isPrimary());
+
+    /*
+     *  1:1 mapping of 'isoform' ranges - not ok
+     */
+    dbr.setMap(new Mapping(null, new int[] { 1, 2, 6, 9 }, new int[] { 1,
+        3, 7, 9 }, 1, 1));
+    assertFalse(dbr.isPrimary());
+    dbr.setMap(null);
+    assertTrue(dbr.isPrimary());
+
     /*
      * Version string is prefixed with another dbref source string (fail)
      */
@@ -163,11 +188,12 @@ public class DBRefEntryTest
     assertTrue(dbr.isPrimary());
 
     /*
-     *  1:1 mapping with shift (fail)
+     * null version string can't be primary ref
      */
-    dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 2, 4 }, 1,
-            1));
+    dbr.setVersion(null);
     assertFalse(dbr.isPrimary());
+    dbr.setVersion("");
+    assertTrue(dbr.isPrimary());
 
     /*
      *  1:1 mapping and sequenceRef (fail)
@@ -182,18 +208,12 @@ public class DBRefEntryTest
     dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 1, 3 }, 1,
             3));
     assertFalse(dbr.isPrimary());
+
     /*
      * 2:2 mapping with shift (expected fail, but maybe use case for a pass)
      */
-    dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 1, 3 }, 2,
+    dbr.setMap(new Mapping(null, new int[] { 1, 4 }, new int[] { 1, 4 }, 2,
             2));
     assertFalse(dbr.isPrimary());
-
-    /*
-     * Version string is prefixed with another dbref source string
-     */
-    dbr.setVersion(DBRefSource.EMBL + ":0");
-    assertFalse(dbr.isPrimary());
-
   }
 }