Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update protein-translation tests #1115

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exercises/protein-translation/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def of_codon(codon):
return CODONS[codon]


def of_rna(strand):
def proteins(strand):
proteins = []
for codon in map(of_codon, _chunkstring(strand, 3)):
if codon == 'STOP':
Expand Down
6 changes: 1 addition & 5 deletions exercises/protein-translation/protein_translation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
def of_codon(codon):
pass


def of_rna(strand):
def proteins(strand):
pass
49 changes: 30 additions & 19 deletions exercises/protein-translation/protein_translation_test.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,69 @@
import unittest

from protein_translation import of_codon, of_rna
from protein_translation import proteins


# Tests adapted from problem-specifications/canonical-data.json @ v1.0.0

class ProteinTranslationTests(unittest.TestCase):

def test_AUG_translates_to_methionine(self):
self.assertEqual('Methionine', of_codon('AUG'))
self.assertEqual(['Methionine'], proteins('AUG'))

def test_identifies_Phenylalanine_codons(self):
for codon in ['UUU', 'UUC']:
self.assertEqual('Phenylalanine', of_codon(codon))
self.assertEqual(['Phenylalanine'], proteins(codon))

def test_identifies_Leucine_codons(self):
for codon in ['UUA', 'UUG']:
self.assertEqual('Leucine', of_codon(codon))
self.assertEqual(['Leucine'], proteins(codon))

def test_identifies_Serine_codons(self):
for codon in ['UCU', 'UCC', 'UCA', 'UCG']:
self.assertEqual('Serine', of_codon(codon))
self.assertEqual(['Serine'], proteins(codon))

def test_identifies_Tyrosine_codons(self):
for codon in ['UAU', 'UAC']:
self.assertEqual('Tyrosine', of_codon(codon))
self.assertEqual(['Tyrosine'], proteins(codon))

def test_identifies_Cysteine_codons(self):
for codon in ['UGU', 'UGC']:
self.assertEqual('Cysteine', of_codon(codon))
self.assertEqual(['Cysteine'], proteins(codon))

def test_identifies_Tryptophan_codons(self):
self.assertEqual('Tryptophan', of_codon('UGG'))
self.assertEqual(['Tryptophan'], proteins('UGG'))

def test_identifies_stop_codons(self):
for codon in ['UAA', 'UAG', 'UGA']:
self.assertEqual('STOP', of_codon(codon))
self.assertEqual([], proteins(codon))

def test_translates_rna_strand_into_correct_protein(self):
def test_translates_rna_strand_into_correct_protein_list(self):
strand = 'AUGUUUUGG'
expected = ['Methionine', 'Phenylalanine', 'Tryptophan']
self.assertEqual(expected, of_rna(strand))
self.assertEqual(expected, proteins(strand))

def test_stops_translation_if_stop_codon_at_beginning_of_sequence(self):
strand = 'UAGUGG'
expected = []
self.assertEqual(expected, proteins(strand))

def test_stops_translation_if_stop_codon_present(self):
def test_stops_translation_if_stop_codon_at_end_of_two_codon_sequence(
self):
strand = 'UGGUAG'
expected = ['Tryptophan']
self.assertEqual(expected, proteins(strand))

def test_stops_translation_if_stop_codon_at_end_of_three_codon_sequence(
self):
strand = 'AUGUUUUAA'
expected = ['Methionine', 'Phenylalanine']
self.assertEqual(expected, of_rna(strand))
self.assertEqual(expected, proteins(strand))

def test_stops_translation_of_longer_strand(self):
def test_stops_translation_if_stop_codon_in_middle_of_six_codon_sequence(
self):
strand = 'UGGUGUUAUUAAUGGUUU'
expected = ['Tryptophan', 'Cysteine', 'Tyrosine']
self.assertEqual(expected, of_rna(strand))

def test_invalid_codons(self):
with self.assertRaises(ValueError):
of_rna('CARROT')
self.assertEqual(expected, proteins(strand))


if __name__ == '__main__':
Expand Down