From 4fdf058790e55b3b2186d05270d7e85c6e224bdd Mon Sep 17 00:00:00 2001 From: Shing Tak Lam Date: Mon, 4 Dec 2017 21:58:22 +0800 Subject: [PATCH 1/4] Edited the 'rna-transcription' exercise to 'rna' and 'dna' --- exercises/rna-transcription/example.rs | 37 ++++++++++++------- .../tests/rna-transcription.rs | 23 +++++++----- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/exercises/rna-transcription/example.rs b/exercises/rna-transcription/example.rs index a747b9f05..3e5b4718b 100644 --- a/exercises/rna-transcription/example.rs +++ b/exercises/rna-transcription/example.rs @@ -1,17 +1,19 @@ #[derive(PartialEq, Eq, Debug)] -pub struct RibonucleicAcid { - nucleotides: String +pub struct RNA { + nucleotides: String, } -impl RibonucleicAcid { - pub fn new(nucleotides: &str) -> RibonucleicAcid { - RibonucleicAcid { nucleotides: nucleotides.to_string() } +impl RNA { + pub fn new(nucleotides: &str) -> RNA { + RNA { + nucleotides: nucleotides.to_string(), + } } } #[derive(PartialEq, Eq, Debug)] -pub struct DeoxyribonucleicAcid { - nucleotides: String +pub struct DNA { + nucleotides: String, } fn transcribe_dna_rna(c: char) -> Option { @@ -20,19 +22,26 @@ fn transcribe_dna_rna(c: char) -> Option { 'G' => Some('C'), 'A' => Some('U'), 'T' => Some('A'), - _ => None + _ => None, } } -impl DeoxyribonucleicAcid { - pub fn new(nucleotides: &str) -> DeoxyribonucleicAcid { - DeoxyribonucleicAcid { nucleotides: nucleotides.to_string() } +impl DNA { + pub fn new(nucleotides: &str) -> DNA { + DNA { + nucleotides: nucleotides.to_string(), + } } - pub fn to_rna(&self) -> Result { - let rna_nucleotides: String = self.nucleotides.chars().filter_map(transcribe_dna_rna).collect(); + pub fn to_rna(&self) -> Result { + let rna_nucleotides: String = self.nucleotides + .chars() + .filter_map(transcribe_dna_rna) + .collect(); if rna_nucleotides.len() == self.nucleotides.len() { - Ok(RibonucleicAcid { nucleotides: rna_nucleotides }) + Ok(RNA { + nucleotides: rna_nucleotides, + }) } else { Err(()) } diff --git a/exercises/rna-transcription/tests/rna-transcription.rs b/exercises/rna-transcription/tests/rna-transcription.rs index 05528f246..1f534d1d4 100644 --- a/exercises/rna-transcription/tests/rna-transcription.rs +++ b/exercises/rna-transcription/tests/rna-transcription.rs @@ -2,54 +2,57 @@ extern crate rna_transcription as dna; #[test] fn test_acid_equals_acid() { - assert_eq!(dna::RibonucleicAcid::new("CGA"), dna::RibonucleicAcid::new("CGA")); - assert_ne!(dna::RibonucleicAcid::new("CGA"), dna::RibonucleicAcid::new("AGC")); + assert_eq!(dna::RNA::new("CGA"), dna::RNA::new("CGA")); + assert_ne!(dna::RNA::new("CGA"), dna::RNA::new("AGC")); } #[test] #[ignore] fn test_transcribes_cytosine_guanine() { - assert_eq!(Ok(dna::RibonucleicAcid::new("G")), dna::DeoxyribonucleicAcid::new("C").to_rna()); + assert_eq!(Ok(dna::RNA::new("G")), dna::DNA::new("C").to_rna()); } #[test] #[ignore] fn test_transcribes_guanine_cytosine() { - assert_eq!(Ok(dna::RibonucleicAcid::new("C")), dna::DeoxyribonucleicAcid::new("G").to_rna()); + assert_eq!(Ok(dna::RNA::new("C")), dna::DNA::new("G").to_rna()); } #[test] #[ignore] fn test_transcribes_adenine_uracil() { - assert_eq!(Ok(dna::RibonucleicAcid::new("U")), dna::DeoxyribonucleicAcid::new("A").to_rna()); + assert_eq!(Ok(dna::RNA::new("U")), dna::DNA::new("A").to_rna()); } #[test] #[ignore] fn test_transcribes_thymine_to_adenine() { - assert_eq!(Ok(dna::RibonucleicAcid::new("A")), dna::DeoxyribonucleicAcid::new("T").to_rna()); + assert_eq!(Ok(dna::RNA::new("A")), dna::DNA::new("T").to_rna()); } #[test] #[ignore] fn test_transcribes_all_dna_to_rna() { - assert_eq!(Ok(dna::RibonucleicAcid::new("UGCACCAGAAUU")), dna::DeoxyribonucleicAcid::new("ACGTGGTCTTAA").to_rna()) + assert_eq!( + Ok(dna::RNA::new("UGCACCAGAAUU")), + dna::DNA::new("ACGTGGTCTTAA").to_rna() + ) } #[test] #[ignore] fn handles_invalid_input() { - assert!(dna::DeoxyribonucleicAcid::new("U").to_rna().is_err()); + assert!(dna::DNA::new("U").to_rna().is_err()); } #[test] #[ignore] fn handles_completely_invalid_input() { - assert!(dna::DeoxyribonucleicAcid::new("XXX").to_rna().is_err()); + assert!(dna::DNA::new("XXX").to_rna().is_err()); } #[test] #[ignore] fn handles_partially_invalid_input() { - assert!(dna::DeoxyribonucleicAcid::new("ACGTXXXCTTAA").to_rna().is_err()); + assert!(dna::DNA::new("ACGTXXXCTTAA").to_rna().is_err()); } From aead1d9b3bc7c560483b0724134ab8658dad4af9 Mon Sep 17 00:00:00 2001 From: Shing Tak Lam Date: Mon, 4 Dec 2017 22:21:34 +0800 Subject: [PATCH 2/4] un-rustfmt-ed the code --- exercises/rna-transcription/example.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/exercises/rna-transcription/example.rs b/exercises/rna-transcription/example.rs index 3e5b4718b..48d5d91c7 100644 --- a/exercises/rna-transcription/example.rs +++ b/exercises/rna-transcription/example.rs @@ -1,19 +1,17 @@ #[derive(PartialEq, Eq, Debug)] pub struct RNA { - nucleotides: String, + nucleotides: String } impl RNA { pub fn new(nucleotides: &str) -> RNA { - RNA { - nucleotides: nucleotides.to_string(), - } + RNA { nucleotides: nucleotides.to_string() } } } #[derive(PartialEq, Eq, Debug)] pub struct DNA { - nucleotides: String, + nucleotides: String } fn transcribe_dna_rna(c: char) -> Option { @@ -22,26 +20,19 @@ fn transcribe_dna_rna(c: char) -> Option { 'G' => Some('C'), 'A' => Some('U'), 'T' => Some('A'), - _ => None, + _ => None, } } impl DNA { pub fn new(nucleotides: &str) -> DNA { - DNA { - nucleotides: nucleotides.to_string(), - } + DNA { nucleotides: nucleotides.to_string() } } pub fn to_rna(&self) -> Result { - let rna_nucleotides: String = self.nucleotides - .chars() - .filter_map(transcribe_dna_rna) - .collect(); + let rna_nucleotides: String = self.nucleotides.chars().filter_map(transcribe_dna_rna).collect(); if rna_nucleotides.len() == self.nucleotides.len() { - Ok(RNA { - nucleotides: rna_nucleotides, - }) + Ok(RNA { nucleotides: rna_nucleotides }) } else { Err(()) } From 0916a42716ca5259028ca3cf3287da72e84a293a Mon Sep 17 00:00:00 2001 From: Shing Tak Lam Date: Mon, 4 Dec 2017 22:23:21 +0800 Subject: [PATCH 3/4] un-rustfmt-ed again --- exercises/rna-transcription/tests/rna-transcription.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/exercises/rna-transcription/tests/rna-transcription.rs b/exercises/rna-transcription/tests/rna-transcription.rs index 1f534d1d4..ab2f9919b 100644 --- a/exercises/rna-transcription/tests/rna-transcription.rs +++ b/exercises/rna-transcription/tests/rna-transcription.rs @@ -33,10 +33,7 @@ fn test_transcribes_thymine_to_adenine() { #[test] #[ignore] fn test_transcribes_all_dna_to_rna() { - assert_eq!( - Ok(dna::RNA::new("UGCACCAGAAUU")), - dna::DNA::new("ACGTGGTCTTAA").to_rna() - ) + assert_eq!(Ok(dna::RNA::new("UGCACCAGAAUU")), dna::DNA::new("ACGTGGTCTTAA").to_rna()) } #[test] From 758ec6dfc8ed5905011e093044870fe57d9c3063 Mon Sep 17 00:00:00 2001 From: Shing Tak Lam Date: Mon, 4 Dec 2017 22:24:39 +0800 Subject: [PATCH 4/4] un-rustfmt try 3 --- exercises/rna-transcription/example.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/rna-transcription/example.rs b/exercises/rna-transcription/example.rs index 48d5d91c7..f9fd10a12 100644 --- a/exercises/rna-transcription/example.rs +++ b/exercises/rna-transcription/example.rs @@ -20,7 +20,7 @@ fn transcribe_dna_rna(c: char) -> Option { 'G' => Some('C'), 'A' => Some('U'), 'T' => Some('A'), - _ => None, + _ => None } }