X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fanalysis%2FAlignSeqTest.java;h=bd827f96d7b5d70dd314b2d0f656c4740a790451;hb=b2a2c2070f14d18d67b07b030d70073a21b7a4e3;hp=d3f4bff4bd74d29c2d2e61cfb58c26374f02061e;hpb=52288466dd1e71946a06fd1e6ea15fa8e652c693;p=jalview.git diff --git a/test/jalview/analysis/AlignSeqTest.java b/test/jalview/analysis/AlignSeqTest.java index d3f4bff..bd827f9 100644 --- a/test/jalview/analysis/AlignSeqTest.java +++ b/test/jalview/analysis/AlignSeqTest.java @@ -1,12 +1,45 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.analysis; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals; +import jalview.datamodel.Sequence; +import jalview.gui.JvOptionPane; + +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class AlignSeqTest { + + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + @Test(groups = { "Functional" }) public void testExtractGaps() { @@ -14,10 +47,33 @@ public class AlignSeqTest assertNull(AlignSeq.extractGaps(null, "ACG")); assertNull(AlignSeq.extractGaps("-. ", null)); - assertEquals(" AC-G.T", AlignSeq.extractGaps("", " AC-G.T")); - assertEquals("AC-G.T", AlignSeq.extractGaps(" ", " AC-G.T")); - assertEquals("ACG.T", AlignSeq.extractGaps(" -", " AC-G.T")); - assertEquals("ACGT", AlignSeq.extractGaps(" -.", " AC-G.T .")); - assertEquals(" ACG.T", AlignSeq.extractGaps("-", " AC-G.T")); + assertEquals(AlignSeq.extractGaps("", " AC-G.T"), " AC-G.T"); + assertEquals(AlignSeq.extractGaps(" ", " AC-G.T"), "AC-G.T"); + assertEquals(AlignSeq.extractGaps(" -", " AC-G.T"), "ACG.T"); + assertEquals(AlignSeq.extractGaps(" -.", " AC-G.T ."), "ACGT"); + assertEquals(AlignSeq.extractGaps("-", " AC-G.T"), " ACG.T"); + assertEquals(AlignSeq.extractGaps("-. ", " -. .-"), ""); + } + + @Test(groups = { "Functional" }) + public void testIndexEncode_nucleotide() + { + AlignSeq as = new AlignSeq(new Sequence("s1", "TTAG"), new Sequence( + "s2", "ACGT"), AlignSeq.DNA); + int[] expected = new int[] { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, + 7, 7, 8, 8, 9, 9, -1, -1, 10, -1 }; + String s = "aAcCgGtTuUiIxXrRyYnN .-?"; + assertArrayEquals(expected, as.indexEncode(s)); + } + + @Test(groups = { "Functional" }) + public void testIndexEncode_peptide() + { + AlignSeq as = new AlignSeq(new Sequence("s1", "PFY"), new Sequence( + "s2", "RQW"), AlignSeq.PEP); + int[] expected = new int[] { 0, 0, 1, 1, 2, 2, 21, 21, 22, 22, -1, 23, + -1, -1, -1 }; + String s = "aArRnNzZxX *.-?"; + assertArrayEquals(expected, as.indexEncode(s)); } }