package jalview.datamodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertSame;
+import static org.testng.AssertJUnit.assertTrue;
import java.util.Arrays;
import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
public class SequenceTest
{
SequenceI seq;
- @Before
+ @BeforeMethod(alwaysRun = true)
public void setUp()
{
seq = new Sequence("FER1", "AKPNGVL");
}
- @Test
+ @Test(groups ={ "Functional" })
public void testInsertGapsAndGapmaps()
{
SequenceI aseq = seq.deriveSequence();
assertEquals("Gap interval 2 end wrong", 8, gapInt.get(1)[1]);
}
- @Test
+ @Test(groups ={ "Functional" })
public void testGetAnnotation()
{
// initial state returns null not an empty array
assertNull(seq.getAnnotation());
}
- @Test
+ @Test(groups ={ "Functional" })
public void testGetAnnotation_forLabel()
{
AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1", 1f);
return annotation;
}
- @Test
+ @Test(groups ={ "Functional" })
public void testGetAlignmentAnnotations_forCalcIdAndLabel()
{
AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
* setting the sequenceRef on the annotation. Adding the same annotation twice
* should be ignored.
*/
- @Test
+ @Test(groups ={ "Functional" })
public void testAddAlignmentAnnotation()
{
assertNull(seq.getAnnotation());
}
- @Test
+ @Test(groups ={ "Functional" })
public void testGetStartGetEnd()
{
SequenceI seq = new Sequence("test", "ABCDEF");
* Tests for the method that returns an alignment column position (base 1) for
* a given sequence position (base 1).
*/
- @Test
+ @Test(groups ={ "Functional" })
public void testFindIndex()
{
SequenceI seq = new Sequence("test", "ABCDEF");
* Tests for the method that returns a dataset sequence position (base 1) for
* an aligned column position (base 0).
*/
- @Test
+ @Test(groups ={ "Functional" })
public void testFindPosition()
{
SequenceI seq = new Sequence("test", "ABCDEF");
assertEquals(7, seq.findPosition(11));
}
- @Test
+ @Test(groups ={ "Functional" })
public void testDeleteChars()
{
SequenceI seq = new Sequence("test", "ABCDEF");
assertEquals(6, seq.getEnd());
}
- @Test
+ @Test(groups ={ "Functional" })
public void testInsertCharAt()
{
// non-static methods:
* Test the method that returns an array of aligned sequence positions where
* the array index is the data sequence position (both base 0).
*/
- @Test
+ @Test(groups ={ "Functional" })
public void testGapMap()
{
SequenceI seq = new Sequence("test", "-A--B-CD-E--F-");
* Test the method that gets sequence features, either from the sequence or
* its dataset.
*/
- @Test
+ @Test(groups ={ "Functional" })
public void testGetSequenceFeatures()
{
SequenceI seq = new Sequence("test", "GATCAT");
seq.getDatasetSequence().setDatasetSequence(seq); // loop!
assertNull(seq.getSequenceFeatures());
}
-}
\ No newline at end of file
+
+ /**
+ * Test the method that returns an array, indexed by sequence position, whose
+ * entries are the residue positions at the sequence position (or to the right
+ * if a gap)
+ */
+ @Test(groups ={ "Functional" })
+ public void testFindPositionMap()
+ {
+ /*
+ * Note: Javadoc for findPosition says it returns the residue position to
+ * the left of a gapped position; in fact it returns the position to the
+ * right. Also it returns a non-existent residue position for a gap beyond
+ * the sequence.
+ */
+ Sequence seq = new Sequence("TestSeq", "AB.C-D E.");
+ int[] map = seq.findPositionMap();
+ assertEquals(Arrays.toString(new int[]
+ { 1, 2, 3, 3, 4, 4, 5, 5, 6 }), Arrays.toString(map));
+ }
+
+ /**
+ * Test for getSubsequence
+ */
+ @Test(groups ={ "Functional" })
+ public void testGetSubsequence()
+ {
+ SequenceI seq = new Sequence("TestSeq", "ABCDEFG");
+ seq.createDatasetSequence();
+
+ // positions are base 0, end position is exclusive
+ SequenceI subseq = seq.getSubSequence(2, 4);
+
+ assertEquals("CD", subseq.getSequenceAsString());
+ // start/end are base 1 positions
+ assertEquals(3, subseq.getStart());
+ assertEquals(4, subseq.getEnd());
+ // subsequence shares the full dataset sequence
+ assertSame(seq.getDatasetSequence(), subseq.getDatasetSequence());
+ }
+
+ /**
+ * Test for deriveSequence applied to a sequence with a dataset
+ */
+ @Test(groups ={ "Functional" })
+ public void testDeriveSequence_existingDataset()
+ {
+ SequenceI seq = new Sequence("Seq1", "CD");
+ seq.setDatasetSequence(new Sequence("Seq1", "ABCDEF"));
+ seq.setStart(3);
+ seq.setEnd(4);
+ SequenceI derived = seq.deriveSequence();
+ assertEquals("CD", derived.getSequenceAsString());
+ assertSame(seq.getDatasetSequence(), derived.getDatasetSequence());
+ }
+
+ /**
+ * Test for deriveSequence applied to an ungapped sequence with no dataset
+ */
+ @Test(groups ={ "Functional" })
+ public void testDeriveSequence_noDatasetUngapped()
+ {
+ SequenceI seq = new Sequence("Seq1", "ABCDEF");
+ assertEquals(1, seq.getStart());
+ assertEquals(6, seq.getEnd());
+ SequenceI derived = seq.deriveSequence();
+ assertEquals("ABCDEF", derived.getSequenceAsString());
+ assertEquals("ABCDEF", derived.getDatasetSequence()
+ .getSequenceAsString());
+ }
+
+ /**
+ * Test for deriveSequence applied to a gapped sequence with no dataset
+ */
+ @Test(groups ={ "Functional" })
+ public void testDeriveSequence_noDatasetGapped()
+ {
+ SequenceI seq = new Sequence("Seq1", "AB-C.D EF");
+ assertEquals(1, seq.getStart());
+ assertEquals(6, seq.getEnd());
+ assertNull(seq.getDatasetSequence());
+ SequenceI derived = seq.deriveSequence();
+ assertEquals("AB-C.D EF", derived.getSequenceAsString());
+ assertEquals("ABCDEF", derived.getDatasetSequence()
+ .getSequenceAsString());
+ }
+}