JAL-3383 JAL-3253-applet
[jalview.git] / test / jalview / datamodel / features / FeatureStoreTest.java
index 6e7dd02..7fe94d0 100644 (file)
@@ -19,7 +19,7 @@ public class FeatureStoreTest
   @Test(groups = "Functional")
   public void testFindFeatures_nonNested()
   {
-    FeatureStore fs = new FeatureStore();
+    FeatureStoreI fs = newFeatureStore();
     fs.addFeature(new SequenceFeature("", "", 10, 20, Float.NaN,
             null));
     // same range different description
@@ -46,10 +46,16 @@ public class FeatureStoreTest
     assertEquals(overlaps.get(0).getEnd(), 35);
   }
 
+  private FeatureStoreI newFeatureStore()
+  {
+    // return new FeatureStoreJS();
+    return new FeatureStoreImpl();
+  }
+
   @Test(groups = "Functional")
   public void testFindFeatures_nested()
   {
-    FeatureStore fs = new FeatureStore();
+    FeatureStoreI fs = newFeatureStore();
     SequenceFeature sf1 = addFeature(fs, 10, 50);
     SequenceFeature sf2 = addFeature(fs, 10, 40);
     SequenceFeature sf3 = addFeature(fs, 20, 30);
@@ -88,7 +94,7 @@ public class FeatureStoreTest
   @Test(groups = "Functional")
   public void testFindFeatures_mixed()
   {
-    FeatureStore fs = new FeatureStore();
+    FeatureStoreI fs = newFeatureStore();
     SequenceFeature sf1 = addFeature(fs, 10, 50);
     SequenceFeature sf2 = addFeature(fs, 1, 15);
     SequenceFeature sf3 = addFeature(fs, 20, 30);
@@ -134,7 +140,7 @@ public class FeatureStoreTest
    * @param to
    * @return
    */
-  SequenceFeature addFeature(FeatureStore fs, int from, int to)
+  SequenceFeature addFeature(FeatureStoreI fs, int from, int to)
   {
     SequenceFeature sf1 = new SequenceFeature("", "", from, to, Float.NaN,
             null);
@@ -145,7 +151,7 @@ public class FeatureStoreTest
   @Test(groups = "Functional")
   public void testFindFeatures_contactFeatures()
   {
-    FeatureStore fs = new FeatureStore();
+    FeatureStoreI fs = newFeatureStore();
 
     SequenceFeature sf = new SequenceFeature("disulphide bond", "bond", 10,
             20, Float.NaN, null);
@@ -185,62 +191,10 @@ public class FeatureStoreTest
     assertTrue(overlaps.contains(sf));
   }
 
-  /**
-   * Tests for the method that returns false for an attempt to add a feature
-   * that would enclose, or be enclosed by, another feature
-   */
-  @Test(groups = "Functional")
-  public void testAddNonNestedFeature()
-  {
-    FeatureStore fs = new FeatureStore();
-
-    String type = "Domain";
-    SequenceFeature sf1 = new SequenceFeature(type, type, 10, 20,
-            Float.NaN, null);
-    assertTrue(fs.addNonNestedFeature(sf1));
-
-    // co-located feature is ok
-    SequenceFeature sf2 = new SequenceFeature(type, type, 10, 20,
-            Float.NaN, null);
-    assertTrue(fs.addNonNestedFeature(sf2));
-
-    // overlap left is ok
-    SequenceFeature sf3 = new SequenceFeature(type, type, 5, 15, Float.NaN,
-            null);
-    assertTrue(fs.addNonNestedFeature(sf3));
-
-    // overlap right is ok
-    SequenceFeature sf4 = new SequenceFeature(type, type, 15, 25,
-            Float.NaN, null);
-    assertTrue(fs.addNonNestedFeature(sf4));
-
-    // add enclosing feature is not ok
-    SequenceFeature sf5 = new SequenceFeature(type, type, 10, 21,
-            Float.NaN, null);
-    assertFalse(fs.addNonNestedFeature(sf5));
-    SequenceFeature sf6 = new SequenceFeature(type, type, 4, 15, Float.NaN,
-            null);
-    assertFalse(fs.addNonNestedFeature(sf6));
-    SequenceFeature sf7 = new SequenceFeature(type, type, 1, 50, Float.NaN,
-            null);
-    assertFalse(fs.addNonNestedFeature(sf7));
-
-    // add enclosed feature is not ok
-    SequenceFeature sf8 = new SequenceFeature(type, type, 10, 19,
-            Float.NaN, null);
-    assertFalse(fs.addNonNestedFeature(sf8));
-    SequenceFeature sf9 = new SequenceFeature(type, type, 16, 25,
-            Float.NaN, null);
-    assertFalse(fs.addNonNestedFeature(sf9));
-    SequenceFeature sf10 = new SequenceFeature(type, type, 7, 7, Float.NaN,
-            null);
-    assertFalse(fs.addNonNestedFeature(sf10));
-  }
-
   @Test(groups = "Functional")
   public void testGetPositionalFeatures()
   {
-    FeatureStore store = new FeatureStore();
+    FeatureStoreI store = newFeatureStore();
     SequenceFeature sf1 = new SequenceFeature("Metal", "desc", 10, 20,
             Float.NaN, null);
     store.addFeature(sf1);
@@ -287,7 +241,7 @@ public class FeatureStoreTest
   @Test(groups = "Functional")
   public void testDelete()
   {
-    FeatureStore store = new FeatureStore();
+    FeatureStoreI store = newFeatureStore();
     SequenceFeature sf1 = addFeature(store, 10, 20);
     assertTrue(store.getPositionalFeatures().contains(sf1));
 
@@ -359,7 +313,7 @@ public class FeatureStoreTest
   @Test(groups = "Functional")
   public void testAddFeature()
   {
-    FeatureStore fs = new FeatureStore();
+    FeatureStoreI fs = newFeatureStore();
 
     SequenceFeature sf1 = new SequenceFeature("Cath", "", 10, 20,
             Float.NaN, null);
@@ -410,7 +364,7 @@ public class FeatureStoreTest
   @Test(groups = "Functional")
   public void testIsEmpty()
   {
-    FeatureStore fs = new FeatureStore();
+    FeatureStoreI fs = newFeatureStore();
     assertTrue(fs.isEmpty());
     assertEquals(fs.getFeatureCount(true), 0);
 
@@ -463,9 +417,7 @@ public class FeatureStoreTest
     assertEquals(fs.getFeatureCount(true), 3);
     assertTrue(fs.delete(sf1));
     assertEquals(fs.getFeatureCount(true), 2);
-    // FeatureStore should now only contain features in the NCList
-    assertTrue(fs.nonNestedFeatures.isEmpty());
-    assertEquals(fs.nestedFeatures.size(), 2);
+    assertEquals(fs.getFeatures().size(), 2);
     assertFalse(fs.isEmpty());
     assertTrue(fs.delete(sf2));
     assertEquals(fs.getFeatureCount(true), 1);
@@ -478,7 +430,7 @@ public class FeatureStoreTest
   @Test(groups = "Functional")
   public void testGetFeatureGroups()
   {
-    FeatureStore fs = new FeatureStore();
+    FeatureStoreI fs = newFeatureStore();
     assertTrue(fs.getFeatureGroups(true).isEmpty());
     assertTrue(fs.getFeatureGroups(false).isEmpty());
 
@@ -545,7 +497,7 @@ public class FeatureStoreTest
   @Test(groups = "Functional")
   public void testGetTotalFeatureLength()
   {
-    FeatureStore fs = new FeatureStore();
+    FeatureStoreI fs = newFeatureStore();
     assertEquals(fs.getTotalFeatureLength(), 0);
 
     addFeature(fs, 10, 20); // 11
@@ -621,7 +573,7 @@ public class FeatureStoreTest
   @Test(groups = "Functional")
   public void testGetMinimumScore_getMaximumScore()
   {
-    FeatureStore fs = new FeatureStore();
+    FeatureStoreI fs = newFeatureStore();
     assertEquals(fs.getMinimumScore(true), Float.NaN); // positional
     assertEquals(fs.getMaximumScore(true), Float.NaN);
     assertEquals(fs.getMinimumScore(false), Float.NaN); // non-positional
@@ -694,7 +646,7 @@ public class FeatureStoreTest
   public void testListContains()
   {
     assertFalse(FeatureStore.listContains(null, null));
-    List<SequenceFeature> features = new ArrayList<SequenceFeature>();
+    List<SequenceFeature> features = new ArrayList<>();
     assertFalse(FeatureStore.listContains(features, null));
 
     SequenceFeature sf1 = new SequenceFeature("type1", "desc1", 20, 30, 3f,
@@ -716,7 +668,7 @@ public class FeatureStoreTest
   @Test(groups = "Functional")
   public void testGetFeaturesForGroup()
   {
-    FeatureStore fs = new FeatureStore();
+    FeatureStoreI fs = newFeatureStore();
 
     /*
      * with no features
@@ -774,7 +726,7 @@ public class FeatureStoreTest
   @Test(groups = "Functional")
   public void testShiftFeatures()
   {
-    FeatureStore fs = new FeatureStore();
+    FeatureStoreI fs = newFeatureStore();
     assertFalse(fs.shiftFeatures(0, 1)); // nothing to do
 
     SequenceFeature sf1 = new SequenceFeature("Cath", "", 2, 5, 0f, null);
@@ -861,7 +813,7 @@ public class FeatureStoreTest
     /*
      * add a feature and a nested feature
      */
-    FeatureStore store = new FeatureStore();
+    FeatureStoreI store = newFeatureStore();
     SequenceFeature sf1 = addFeature(store, 10, 20);
     // sf2 is nested in sf1 so will be stored in nestedFeatures
     SequenceFeature sf2 = addFeature(store, 12, 14);
@@ -869,8 +821,8 @@ public class FeatureStoreTest
     assertEquals(features.size(), 2);
     assertTrue(features.contains(sf1));
     assertTrue(features.contains(sf2));
-    assertTrue(store.nonNestedFeatures.contains(sf1));
-    assertTrue(store.nestedFeatures.contains(sf2));
+    assertTrue(store.getFeatures().contains(sf1));
+    assertTrue(store.getFeatures().contains(sf2));
   
     /*
      * delete the first feature
@@ -892,7 +844,7 @@ public class FeatureStoreTest
   @Test(groups = "Functional")
   public void testContains()
   {
-    FeatureStore fs = new FeatureStore();
+    FeatureStoreI fs = newFeatureStore();
     SequenceFeature sf1 = new SequenceFeature("Cath", "", 10, 20,
             Float.NaN, "group1");
     SequenceFeature sf2 = new SequenceFeature("Cath", "", 10, 20,