|
1 | 1 | import unittest |
2 | 2 |
|
3 | | -from protein_translation import of_codon, of_rna |
| 3 | +from protein_translation import proteins |
4 | 4 |
|
5 | 5 |
|
| 6 | +# Tests adapted from problem-specifications/canonical-data.json @ v1.0.0 |
| 7 | + |
6 | 8 | class ProteinTranslationTests(unittest.TestCase): |
7 | 9 |
|
8 | 10 | def test_AUG_translates_to_methionine(self): |
9 | | - self.assertEqual('Methionine', of_codon('AUG')) |
| 11 | + self.assertEqual(['Methionine'], proteins('AUG')) |
10 | 12 |
|
11 | 13 | def test_identifies_Phenylalanine_codons(self): |
12 | 14 | for codon in ['UUU', 'UUC']: |
13 | | - self.assertEqual('Phenylalanine', of_codon(codon)) |
| 15 | + self.assertEqual(['Phenylalanine'], proteins(codon)) |
14 | 16 |
|
15 | 17 | def test_identifies_Leucine_codons(self): |
16 | 18 | for codon in ['UUA', 'UUG']: |
17 | | - self.assertEqual('Leucine', of_codon(codon)) |
| 19 | + self.assertEqual(['Leucine'], proteins(codon)) |
18 | 20 |
|
19 | 21 | def test_identifies_Serine_codons(self): |
20 | 22 | for codon in ['UCU', 'UCC', 'UCA', 'UCG']: |
21 | | - self.assertEqual('Serine', of_codon(codon)) |
| 23 | + self.assertEqual(['Serine'], proteins(codon)) |
22 | 24 |
|
23 | 25 | def test_identifies_Tyrosine_codons(self): |
24 | 26 | for codon in ['UAU', 'UAC']: |
25 | | - self.assertEqual('Tyrosine', of_codon(codon)) |
| 27 | + self.assertEqual(['Tyrosine'], proteins(codon)) |
26 | 28 |
|
27 | 29 | def test_identifies_Cysteine_codons(self): |
28 | 30 | for codon in ['UGU', 'UGC']: |
29 | | - self.assertEqual('Cysteine', of_codon(codon)) |
| 31 | + self.assertEqual(['Cysteine'], proteins(codon)) |
30 | 32 |
|
31 | 33 | def test_identifies_Tryptophan_codons(self): |
32 | | - self.assertEqual('Tryptophan', of_codon('UGG')) |
| 34 | + self.assertEqual(['Tryptophan'], proteins('UGG')) |
33 | 35 |
|
34 | 36 | def test_identifies_stop_codons(self): |
35 | 37 | for codon in ['UAA', 'UAG', 'UGA']: |
36 | | - self.assertEqual('STOP', of_codon(codon)) |
| 38 | + self.assertEqual([], proteins(codon)) |
37 | 39 |
|
38 | | - def test_translates_rna_strand_into_correct_protein(self): |
| 40 | + def test_translates_rna_strand_into_correct_protein_list(self): |
39 | 41 | strand = 'AUGUUUUGG' |
40 | 42 | expected = ['Methionine', 'Phenylalanine', 'Tryptophan'] |
41 | | - self.assertEqual(expected, of_rna(strand)) |
| 43 | + self.assertEqual(expected, proteins(strand)) |
| 44 | + |
| 45 | + def test_stops_translation_if_stop_codon_at_beginning_of_sequence(self): |
| 46 | + strand = 'UAGUGG' |
| 47 | + expected = [] |
| 48 | + self.assertEqual(expected, proteins(strand)) |
42 | 49 |
|
43 | | - def test_stops_translation_if_stop_codon_present(self): |
| 50 | + def test_stops_translation_if_stop_codon_at_end_of_two_codon_sequence( |
| 51 | + self): |
| 52 | + strand = 'UGGUAG' |
| 53 | + expected = ['Tryptophan'] |
| 54 | + self.assertEqual(expected, proteins(strand)) |
| 55 | + |
| 56 | + def test_stops_translation_if_stop_codon_at_end_of_three_codon_sequence( |
| 57 | + self): |
44 | 58 | strand = 'AUGUUUUAA' |
45 | 59 | expected = ['Methionine', 'Phenylalanine'] |
46 | | - self.assertEqual(expected, of_rna(strand)) |
| 60 | + self.assertEqual(expected, proteins(strand)) |
47 | 61 |
|
48 | | - def test_stops_translation_of_longer_strand(self): |
| 62 | + def test_stops_translation_if_stop_codon_in_middle_of_six_codon_sequence( |
| 63 | + self): |
49 | 64 | strand = 'UGGUGUUAUUAAUGGUUU' |
50 | 65 | expected = ['Tryptophan', 'Cysteine', 'Tyrosine'] |
51 | | - self.assertEqual(expected, of_rna(strand)) |
52 | | - |
53 | | - def test_invalid_codons(self): |
54 | | - with self.assertRaises(ValueError): |
55 | | - of_rna('CARROT') |
| 66 | + self.assertEqual(expected, proteins(strand)) |
56 | 67 |
|
57 | 68 |
|
58 | 69 | if __name__ == '__main__': |
|
0 commit comments