import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
-import jalview.datamodel.SequenceFeature;
-
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.testng.annotations.Test;
+import jalview.datamodel.SequenceFeature;
import junit.extensions.PA;
public class SequenceFeaturesTest
public void testSortFeatures()
{
List<SequenceFeature> sfs = new ArrayList<>();
- SequenceFeature sf1 = new SequenceFeature("Pfam", "desc", 30, 80,
+ SequenceFeature sf1 = new SequenceFeature("Pfam", "desc", 30,
+ 60,
Float.NaN, null);
sfs.add(sf1);
SequenceFeature sf2 = new SequenceFeature("Rfam", "desc", 40, 50,
SequenceFeature sf3 = new SequenceFeature("Rfam", "desc", 50, 60,
Float.NaN, null);
sfs.add(sf3);
+ SequenceFeature sf4 = new SequenceFeature("Xfam", "desc", 30,
+ 80,
+ Float.NaN, null);
+ sfs.add(sf4);
+ SequenceFeature sf5 = new SequenceFeature("Xfam", "desc", 30,
+ 90,
+ Float.NaN, null);
+ sfs.add(sf5);
- // sort by end position descending
+ /*
+ * sort by end position descending, order unchanged if matched
+ */
SequenceFeatures.sortFeatures(sfs, false);
- assertSame(sfs.get(0), sf1);
- assertSame(sfs.get(1), sf3);
- assertSame(sfs.get(2), sf2);
+ assertSame(sfs.get(0), sf5); // end 90
+ assertSame(sfs.get(1), sf4); // end 80
+ assertSame(sfs.get(2), sf1); // end 60, start 50
+ assertSame(sfs.get(3), sf3); // end 60, start 30
+ assertSame(sfs.get(4), sf2); // end 50
- // sort by start position ascending
+ /*
+ * resort {5, 4, 1, 3, 2} by start position ascending, end descending
+ */
SequenceFeatures.sortFeatures(sfs, true);
- assertSame(sfs.get(0), sf1);
- assertSame(sfs.get(1), sf2);
- assertSame(sfs.get(2), sf3);
+ assertSame(sfs.get(0), sf5); // start 30, end 90
+ assertSame(sfs.get(1), sf4); // start 30, end 80
+ assertSame(sfs.get(2), sf1); // start 30, end 60
+ assertSame(sfs.get(3), sf2); // start 40
+ assertSame(sfs.get(4), sf3); // start 50
}
@Test(groups = "Functional")