From 6899ed15fc1d329a34b581a37a202383a7d57b21 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Tue, 15 Aug 2017 17:11:46 -0500 Subject: [PATCH] Python work --- python/rna-transcription/README.md | 36 +++++++++++++++++++ python/rna-transcription/rna_transcription.py | 2 ++ .../rna_transcription_test.py | 35 ++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 python/rna-transcription/README.md create mode 100644 python/rna-transcription/rna_transcription.py create mode 100644 python/rna-transcription/rna_transcription_test.py diff --git a/python/rna-transcription/README.md b/python/rna-transcription/README.md new file mode 100644 index 0000000..394d480 --- /dev/null +++ b/python/rna-transcription/README.md @@ -0,0 +1,36 @@ +# Rna Transcription + +Given a DNA strand, return its RNA complement (per RNA transcription). + +Both DNA and RNA strands are a sequence of nucleotides. + +The four nucleotides found in DNA are adenine (**A**), cytosine (**C**), +guanine (**G**) and thymine (**T**). + +The four nucleotides found in RNA are adenine (**A**), cytosine (**C**), +guanine (**G**) and uracil (**U**). + +Given a DNA strand, its transcribed RNA strand is formed by replacing +each nucleotide with its complement: + +* `G` -> `C` +* `C` -> `G` +* `T` -> `A` +* `A` -> `U` + +### Submitting Exercises + +Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/` directory. + +For example, if you're submitting `bob.py` for the Bob exercise, the submit command would be something like `exercism submit /python/bob/bob.py`. + + +For more detailed information about running tests, code style and linting, +please see the [help page](http://exercism.io/languages/python). + +## Source + +Rosalind [http://rosalind.info/problems/rna](http://rosalind.info/problems/rna) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/python/rna-transcription/rna_transcription.py b/python/rna-transcription/rna_transcription.py new file mode 100644 index 0000000..b7f4db8 --- /dev/null +++ b/python/rna-transcription/rna_transcription.py @@ -0,0 +1,2 @@ +def to_rna(): + pass diff --git a/python/rna-transcription/rna_transcription_test.py b/python/rna-transcription/rna_transcription_test.py new file mode 100644 index 0000000..d078849 --- /dev/null +++ b/python/rna-transcription/rna_transcription_test.py @@ -0,0 +1,35 @@ +import unittest + +from rna_transcription import to_rna + + +# test cases adapted from `x-common//canonical-data.json` @ version: 1.0.0 + +class DNATests(unittest.TestCase): + def test_transcribes_guanine_to_cytosine(self): + self.assertEqual(to_rna('G'), 'C') + + def test_transcribes_cytosine_to_guanine(self): + self.assertEqual(to_rna('C'), 'G') + + def test_transcribes_thymine_to_adenine(self): + self.assertEqual(to_rna('T'), 'A') + + def test_transcribes_adenine_to_uracil(self): + self.assertEqual(to_rna('A'), 'U') + + def test_transcribes_all_occurences(self): + self.assertMultiLineEqual(to_rna('ACGTGGTCTTAA'), 'UGCACCAGAAUU') + + def test_correctly_handles_single_invalid_input(self): + self.assertEqual(to_rna('U'), '') + + def test_correctly_handles_completely_invalid_input(self): + self.assertMultiLineEqual(to_rna('XXX'), '') + + def test_correctly_handles_partially_invalid_input(self): + self.assertMultiLineEqual(to_rna('ACGTXXXCTTAA'), '') + + +if __name__ == '__main__': + unittest.main()