JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / test / jalview / analysis / CodingUtilsTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 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 java.util.Arrays;
27
28 import org.testng.annotations.Test;
29
30 public class CodingUtilsTest
31 {
32
33   @Test(groups = { "Functional" })
34   public void testDecodeCodon()
35   {
36     assertTrue(Arrays.equals(new char[] { 'A', 'A', 'A' },
37             CodingUtils.decodeCodon(0)));
38     assertTrue(Arrays.equals(new char[] { 'A', 'A', 'C' },
39             CodingUtils.decodeCodon(1)));
40     assertTrue(Arrays.equals(new char[] { 'A', 'A', 'G' },
41             CodingUtils.decodeCodon(2)));
42     assertTrue(Arrays.equals(new char[] { 'A', 'A', 'T' },
43             CodingUtils.decodeCodon(3)));
44     assertTrue(Arrays.equals(new char[] { 'A', 'C', 'A' },
45             CodingUtils.decodeCodon(4)));
46     assertTrue(Arrays.equals(new char[] { 'C', 'A', 'A' },
47             CodingUtils.decodeCodon(16)));
48     assertTrue(Arrays.equals(new char[] { 'G', 'G', 'G' },
49             CodingUtils.decodeCodon(42)));
50     assertTrue(Arrays.equals(new char[] { 'T', 'T', 'T' },
51             CodingUtils.decodeCodon(63)));
52   }
53
54   @Test(groups = { "Functional" })
55   public void testDecodeNucleotide()
56   {
57     assertEquals('A', CodingUtils.decodeNucleotide(0));
58     assertEquals('C', CodingUtils.decodeNucleotide(1));
59     assertEquals('G', CodingUtils.decodeNucleotide(2));
60     assertEquals('T', CodingUtils.decodeNucleotide(3));
61     assertEquals('0', CodingUtils.decodeNucleotide(4));
62   }
63
64   @Test(groups = { "Functional" })
65   public void testEncodeCodon()
66   {
67     assertTrue(CodingUtils.encodeCodon('Z') < 0);
68     assertEquals(0, CodingUtils.encodeCodon('a'));
69     assertEquals(0, CodingUtils.encodeCodon('A'));
70     assertEquals(1, CodingUtils.encodeCodon('c'));
71     assertEquals(1, CodingUtils.encodeCodon('C'));
72     assertEquals(2, CodingUtils.encodeCodon('g'));
73     assertEquals(2, CodingUtils.encodeCodon('G'));
74     assertEquals(3, CodingUtils.encodeCodon('t'));
75     assertEquals(3, CodingUtils.encodeCodon('T'));
76     assertEquals(3, CodingUtils.encodeCodon('u'));
77     assertEquals(3, CodingUtils.encodeCodon('U'));
78
79     assertEquals(-1, CodingUtils.encodeCodon(null));
80     assertEquals(0, CodingUtils.encodeCodon(new char[] { 'A', 'A', 'A' }));
81     assertEquals(1, CodingUtils.encodeCodon(new char[] { 'A', 'A', 'C' }));
82     assertEquals(2, CodingUtils.encodeCodon(new char[] { 'A', 'A', 'G' }));
83     assertEquals(3, CodingUtils.encodeCodon(new char[] { 'A', 'A', 'T' }));
84     assertEquals(4, CodingUtils.encodeCodon(new char[] { 'A', 'C', 'A' }));
85     assertEquals(16, CodingUtils.encodeCodon(new char[] { 'C', 'A', 'A' }));
86     assertEquals(42, CodingUtils.encodeCodon(new char[] { 'G', 'G', 'G' }));
87     assertEquals(63, CodingUtils.encodeCodon(new char[] { 'T', 'T', 'T' }));
88   }
89
90 }