From 63122ddc672e2d287b9cc0e7752675cb0f70f7cf Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Wed, 30 Dec 2020 09:17:15 +0000 Subject: [rust] RNA Transcription --- rust/rna-transcription/tests/rna-transcription.rs | 79 +++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 rust/rna-transcription/tests/rna-transcription.rs (limited to 'rust/rna-transcription/tests') diff --git a/rust/rna-transcription/tests/rna-transcription.rs b/rust/rna-transcription/tests/rna-transcription.rs new file mode 100644 index 0000000..bc96a4f --- /dev/null +++ b/rust/rna-transcription/tests/rna-transcription.rs @@ -0,0 +1,79 @@ +use rna_transcription as dna; + +#[test] +fn test_valid_dna_input() { + assert!(dna::Dna::new("GCTA").is_ok()); +} + +#[test] +fn test_valid_rna_input() { + assert!(dna::Rna::new("CGAU").is_ok()); +} + +#[test] +fn test_invalid_dna_input() { + // Invalid character + assert_eq!(dna::Dna::new("X").err(), Some(0)); + // Valid nucleotide, but invalid in context + assert_eq!(dna::Dna::new("U").err(), Some(0)); + // Longer string with contained errors + assert_eq!(dna::Dna::new("ACGTUXXCTTAA").err(), Some(4)); +} + +#[test] +fn test_invalid_rna_input() { + // Invalid character + assert_eq!(dna::Rna::new("X").unwrap_err(), 0); + // Valid nucleotide, but invalid in context + assert_eq!(dna::Rna::new("T").unwrap_err(), 0); + // Longer string with contained errors + assert_eq!(dna::Rna::new("ACGUTTXCUUAA").unwrap_err(), 4); +} + +#[test] +fn test_acid_equals_acid() { + assert_eq!(dna::Dna::new("CGA").unwrap(), dna::Dna::new("CGA").unwrap()); + assert_ne!(dna::Dna::new("CGA").unwrap(), dna::Dna::new("AGC").unwrap()); + assert_eq!(dna::Rna::new("CGA").unwrap(), dna::Rna::new("CGA").unwrap()); + assert_ne!(dna::Rna::new("CGA").unwrap(), dna::Rna::new("AGC").unwrap()); +} + +#[test] +fn test_transcribes_cytosine_guanine() { + assert_eq!( + dna::Rna::new("G").unwrap(), + dna::Dna::new("C").unwrap().into_rna() + ); +} + +#[test] +fn test_transcribes_guanine_cytosine() { + assert_eq!( + dna::Rna::new("C").unwrap(), + dna::Dna::new("G").unwrap().into_rna() + ); +} + +#[test] +fn test_transcribes_adenine_uracil() { + assert_eq!( + dna::Rna::new("U").unwrap(), + dna::Dna::new("A").unwrap().into_rna() + ); +} + +#[test] +fn test_transcribes_thymine_to_adenine() { + assert_eq!( + dna::Rna::new("A").unwrap(), + dna::Dna::new("T").unwrap().into_rna() + ); +} + +#[test] +fn test_transcribes_all_dna_to_rna() { + assert_eq!( + dna::Rna::new("UGCACCAGAAUU").unwrap(), + dna::Dna::new("ACGTGGTCTTAA").unwrap().into_rna() + ) +} -- cgit v1.2.3