JAL-3438 spotless for 2.11.2.0
[jalview.git] / test / jalview / analysis / CodingUtilsTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.analysis;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
25
26 import jalview.gui.JvOptionPane;
27
28 import java.util.Arrays;
29
30 import org.testng.annotations.BeforeClass;
31 import org.testng.annotations.Test;
32
33 public class CodingUtilsTest
34 {
35
36   @BeforeClass(alwaysRun = true)
37   public void setUpJvOptionPane()
38   {
39     JvOptionPane.setInteractiveMode(false);
40     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
41   }
42
43   @Test(groups = { "Functional" })
44   public void testDecodeCodon()
45   {
46     assertTrue(
47             Arrays.equals(new char[]
48             { 'A', 'A', 'A' }, CodingUtils.decodeCodon(0)));
49     assertTrue(
50             Arrays.equals(new char[]
51             { 'A', 'A', 'C' }, CodingUtils.decodeCodon(1)));
52     assertTrue(
53             Arrays.equals(new char[]
54             { 'A', 'A', 'G' }, CodingUtils.decodeCodon(2)));
55     assertTrue(
56             Arrays.equals(new char[]
57             { 'A', 'A', 'T' }, CodingUtils.decodeCodon(3)));
58     assertTrue(
59             Arrays.equals(new char[]
60             { 'A', 'C', 'A' }, CodingUtils.decodeCodon(4)));
61     assertTrue(
62             Arrays.equals(new char[]
63             { 'C', 'A', 'A' }, CodingUtils.decodeCodon(16)));
64     assertTrue(
65             Arrays.equals(new char[]
66             { 'G', 'G', 'G' }, CodingUtils.decodeCodon(42)));
67     assertTrue(
68             Arrays.equals(new char[]
69             { 'T', 'T', 'T' }, CodingUtils.decodeCodon(63)));
70   }
71
72   @Test(groups = { "Functional" })
73   public void testDecodeNucleotide()
74   {
75     assertEquals('A', CodingUtils.decodeNucleotide(0));
76     assertEquals('C', CodingUtils.decodeNucleotide(1));
77     assertEquals('G', CodingUtils.decodeNucleotide(2));
78     assertEquals('T', CodingUtils.decodeNucleotide(3));
79     assertEquals('0', CodingUtils.decodeNucleotide(4));
80   }
81
82   @Test(groups = { "Functional" })
83   public void testEncodeCodon()
84   {
85     assertTrue(CodingUtils.encodeCodon('Z') < 0);
86     assertEquals(0, CodingUtils.encodeCodon('a'));
87     assertEquals(0, CodingUtils.encodeCodon('A'));
88     assertEquals(1, CodingUtils.encodeCodon('c'));
89     assertEquals(1, CodingUtils.encodeCodon('C'));
90     assertEquals(2, CodingUtils.encodeCodon('g'));
91     assertEquals(2, CodingUtils.encodeCodon('G'));
92     assertEquals(3, CodingUtils.encodeCodon('t'));
93     assertEquals(3, CodingUtils.encodeCodon('T'));
94     assertEquals(3, CodingUtils.encodeCodon('u'));
95     assertEquals(3, CodingUtils.encodeCodon('U'));
96
97     assertEquals(-1, CodingUtils.encodeCodon(null));
98     assertEquals(0, CodingUtils.encodeCodon(new char[] { 'A', 'A', 'A' }));
99     assertEquals(1, CodingUtils.encodeCodon(new char[] { 'A', 'A', 'C' }));
100     assertEquals(2, CodingUtils.encodeCodon(new char[] { 'A', 'A', 'G' }));
101     assertEquals(3, CodingUtils.encodeCodon(new char[] { 'A', 'A', 'T' }));
102     assertEquals(4, CodingUtils.encodeCodon(new char[] { 'A', 'C', 'A' }));
103     assertEquals(16, CodingUtils.encodeCodon(new char[] { 'C', 'A', 'A' }));
104     assertEquals(42, CodingUtils.encodeCodon(new char[] { 'G', 'G', 'G' }));
105     assertEquals(63, CodingUtils.encodeCodon(new char[] { 'T', 'T', 'T' }));
106   }
107
108 }