Skip to content

Commit e78fd80

Browse files
sjwarner-bpcmccandless
authored andcommitted
protein-translation: update tests to v1.0.1 (exercism#1115)
* Update protein-translation tests * Fix formatting issues * protein-translation: remove testing of intermediate results * protein-translation: adjust spacing
1 parent 37dd4ea commit e78fd80

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

exercises/protein-translation/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def of_codon(codon):
1212
return CODONS[codon]
1313

1414

15-
def of_rna(strand):
15+
def proteins(strand):
1616
proteins = []
1717
for codon in map(of_codon, _chunkstring(strand, 3)):
1818
if codon == 'STOP':
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
def of_codon(codon):
2-
pass
3-
4-
5-
def of_rna(strand):
1+
def proteins(strand):
62
pass

exercises/protein-translation/protein_translation_test.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,69 @@
11
import unittest
22

3-
from protein_translation import of_codon, of_rna
3+
from protein_translation import proteins
44

55

6+
# Tests adapted from problem-specifications/canonical-data.json @ v1.0.0
7+
68
class ProteinTranslationTests(unittest.TestCase):
79

810
def test_AUG_translates_to_methionine(self):
9-
self.assertEqual('Methionine', of_codon('AUG'))
11+
self.assertEqual(['Methionine'], proteins('AUG'))
1012

1113
def test_identifies_Phenylalanine_codons(self):
1214
for codon in ['UUU', 'UUC']:
13-
self.assertEqual('Phenylalanine', of_codon(codon))
15+
self.assertEqual(['Phenylalanine'], proteins(codon))
1416

1517
def test_identifies_Leucine_codons(self):
1618
for codon in ['UUA', 'UUG']:
17-
self.assertEqual('Leucine', of_codon(codon))
19+
self.assertEqual(['Leucine'], proteins(codon))
1820

1921
def test_identifies_Serine_codons(self):
2022
for codon in ['UCU', 'UCC', 'UCA', 'UCG']:
21-
self.assertEqual('Serine', of_codon(codon))
23+
self.assertEqual(['Serine'], proteins(codon))
2224

2325
def test_identifies_Tyrosine_codons(self):
2426
for codon in ['UAU', 'UAC']:
25-
self.assertEqual('Tyrosine', of_codon(codon))
27+
self.assertEqual(['Tyrosine'], proteins(codon))
2628

2729
def test_identifies_Cysteine_codons(self):
2830
for codon in ['UGU', 'UGC']:
29-
self.assertEqual('Cysteine', of_codon(codon))
31+
self.assertEqual(['Cysteine'], proteins(codon))
3032

3133
def test_identifies_Tryptophan_codons(self):
32-
self.assertEqual('Tryptophan', of_codon('UGG'))
34+
self.assertEqual(['Tryptophan'], proteins('UGG'))
3335

3436
def test_identifies_stop_codons(self):
3537
for codon in ['UAA', 'UAG', 'UGA']:
36-
self.assertEqual('STOP', of_codon(codon))
38+
self.assertEqual([], proteins(codon))
3739

38-
def test_translates_rna_strand_into_correct_protein(self):
40+
def test_translates_rna_strand_into_correct_protein_list(self):
3941
strand = 'AUGUUUUGG'
4042
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))
4249

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):
4458
strand = 'AUGUUUUAA'
4559
expected = ['Methionine', 'Phenylalanine']
46-
self.assertEqual(expected, of_rna(strand))
60+
self.assertEqual(expected, proteins(strand))
4761

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):
4964
strand = 'UGGUGUUAUUAAUGGUUU'
5065
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))
5667

5768

5869
if __name__ == '__main__':

0 commit comments

Comments
 (0)