Skip to content

Commit 4d7c84d

Browse files
authored
Correct naming conventions in rna-transcription exercise (#991)
* Correct naming conventions in rna-transcription exercise Closes #986 * Revert camel-casing for comments
1 parent 85a7c22 commit 4d7c84d

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

exercises/rna-transcription/example.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ impl Nucleotide {
2828
///
2929
/// Guaranteed that Uracil is not present thanks to `new`.
3030
#[derive(Debug, Eq, PartialEq, Clone)]
31-
pub struct DNA(Vec<Nucleotide>);
31+
pub struct Dna(Vec<Nucleotide>);
3232

33-
impl DNA {
33+
impl Dna {
3434
/// Parse a DNA string, checking it is valid.
3535
///
3636
/// The error value is the first invalid character index (char index, not utf8).
37-
pub fn new(input: &str) -> Result<DNA, usize> {
37+
pub fn new(input: &str) -> Result<Dna, usize> {
3838
let mut out = Vec::new();
3939
for (idx, ch) in input.chars().enumerate() {
4040
match Nucleotide::from_char(ch) {
@@ -46,10 +46,10 @@ impl DNA {
4646
}
4747
}
4848
}
49-
Ok(DNA(out))
49+
Ok(Dna(out))
5050
}
5151

52-
pub fn into_rna(mut self) -> RNA {
52+
pub fn into_rna(mut self) -> Rna {
5353
for nuc in self.0.iter_mut() {
5454
*nuc = match *nuc {
5555
Nucleotide::Adenine => Nucleotide::Uracil,
@@ -59,18 +59,18 @@ impl DNA {
5959
Nucleotide::Uracil => unreachable!(),
6060
}
6161
}
62-
RNA(self.0)
62+
Rna(self.0)
6363
}
6464
}
6565

6666
#[derive(Debug, Eq, PartialEq, Clone)]
67-
pub struct RNA(Vec<Nucleotide>);
67+
pub struct Rna(Vec<Nucleotide>);
6868

69-
impl RNA {
69+
impl Rna {
7070
/// Parse a RNA string, checking it is valid.
7171
///
7272
/// The error value is the first invalid character index (char index, not utf8).
73-
pub fn new(input: &str) -> Result<RNA, usize> {
73+
pub fn new(input: &str) -> Result<Rna, usize> {
7474
let mut out = Vec::new();
7575
for (idx, ch) in input.chars().enumerate() {
7676
match Nucleotide::from_char(ch) {
@@ -82,6 +82,6 @@ impl RNA {
8282
}
8383
}
8484
}
85-
Ok(RNA(out))
85+
Ok(Rna(out))
8686
}
8787
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#[derive(Debug, PartialEq)]
2-
pub struct DNA;
2+
pub struct Dna;
33

44
#[derive(Debug, PartialEq)]
5-
pub struct RNA;
5+
pub struct Rna;
66

7-
impl DNA {
8-
pub fn new(dna: &str) -> Result<DNA, usize> {
9-
unimplemented!("Construct new DNA from '{}' string. If string contains invalid nucleotides return index of first invalid nucleotide", dna);
7+
impl Dna {
8+
pub fn new(dna: &str) -> Result<Dna, usize> {
9+
unimplemented!("Construct new Dna from '{}' string. If string contains invalid nucleotides return index of first invalid nucleotide", dna);
1010
}
1111

12-
pub fn into_rna(self) -> RNA {
13-
unimplemented!("Transform DNA {:?} into corresponding RNA", self);
12+
pub fn into_rna(self) -> Rna {
13+
unimplemented!("Transform Dna {:?} into corresponding Rna", self);
1414
}
1515
}
1616

17-
impl RNA {
18-
pub fn new(rna: &str) -> Result<RNA, usize> {
19-
unimplemented!("Construct new RNA from '{}' string. If string contains invalid nucleotides return index of first invalid nucleotide", rna);
17+
impl Rna {
18+
pub fn new(rna: &str) -> Result<Rna, usize> {
19+
unimplemented!("Construct new Rna from '{}' string. If string contains invalid nucleotides return index of first invalid nucleotide", rna);
2020
}
2121
}

exercises/rna-transcription/tests/rna-transcription.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,87 +2,87 @@ use rna_transcription as dna;
22

33
#[test]
44
fn test_valid_dna_input() {
5-
assert!(dna::DNA::new("GCTA").is_ok());
5+
assert!(dna::Dna::new("GCTA").is_ok());
66
}
77

88
#[test]
99
#[ignore]
1010
fn test_valid_rna_input() {
11-
assert!(dna::RNA::new("CGAU").is_ok());
11+
assert!(dna::Rna::new("CGAU").is_ok());
1212
}
1313

1414
#[test]
1515
#[ignore]
1616
fn test_invalid_dna_input() {
1717
// Invalid character
18-
assert_eq!(dna::DNA::new("X").err(), Some(0));
18+
assert_eq!(dna::Dna::new("X").err(), Some(0));
1919
// Valid nucleotide, but invalid in context
20-
assert_eq!(dna::DNA::new("U").err(), Some(0));
20+
assert_eq!(dna::Dna::new("U").err(), Some(0));
2121
// Longer string with contained errors
22-
assert_eq!(dna::DNA::new("ACGTUXXCTTAA").err(), Some(4));
22+
assert_eq!(dna::Dna::new("ACGTUXXCTTAA").err(), Some(4));
2323
}
2424

2525
#[test]
2626
#[ignore]
2727
fn test_invalid_rna_input() {
2828
// Invalid character
29-
assert_eq!(dna::RNA::new("X").unwrap_err(), 0);
29+
assert_eq!(dna::Rna::new("X").unwrap_err(), 0);
3030
// Valid nucleotide, but invalid in context
31-
assert_eq!(dna::RNA::new("T").unwrap_err(), 0);
31+
assert_eq!(dna::Rna::new("T").unwrap_err(), 0);
3232
// Longer string with contained errors
33-
assert_eq!(dna::RNA::new("ACGUTTXCUUAA").unwrap_err(), 4);
33+
assert_eq!(dna::Rna::new("ACGUTTXCUUAA").unwrap_err(), 4);
3434
}
3535

3636
#[test]
3737
#[ignore]
3838
fn test_acid_equals_acid() {
39-
assert_eq!(dna::DNA::new("CGA").unwrap(), dna::DNA::new("CGA").unwrap());
40-
assert_ne!(dna::DNA::new("CGA").unwrap(), dna::DNA::new("AGC").unwrap());
41-
assert_eq!(dna::RNA::new("CGA").unwrap(), dna::RNA::new("CGA").unwrap());
42-
assert_ne!(dna::RNA::new("CGA").unwrap(), dna::RNA::new("AGC").unwrap());
39+
assert_eq!(dna::Dna::new("CGA").unwrap(), dna::Dna::new("CGA").unwrap());
40+
assert_ne!(dna::Dna::new("CGA").unwrap(), dna::Dna::new("AGC").unwrap());
41+
assert_eq!(dna::Rna::new("CGA").unwrap(), dna::Rna::new("CGA").unwrap());
42+
assert_ne!(dna::Rna::new("CGA").unwrap(), dna::Rna::new("AGC").unwrap());
4343
}
4444

4545
#[test]
4646
#[ignore]
4747
fn test_transcribes_cytosine_guanine() {
4848
assert_eq!(
49-
dna::RNA::new("G").unwrap(),
50-
dna::DNA::new("C").unwrap().into_rna()
49+
dna::Rna::new("G").unwrap(),
50+
dna::Dna::new("C").unwrap().into_rna()
5151
);
5252
}
5353

5454
#[test]
5555
#[ignore]
5656
fn test_transcribes_guanine_cytosine() {
5757
assert_eq!(
58-
dna::RNA::new("C").unwrap(),
59-
dna::DNA::new("G").unwrap().into_rna()
58+
dna::Rna::new("C").unwrap(),
59+
dna::Dna::new("G").unwrap().into_rna()
6060
);
6161
}
6262

6363
#[test]
6464
#[ignore]
6565
fn test_transcribes_adenine_uracil() {
6666
assert_eq!(
67-
dna::RNA::new("U").unwrap(),
68-
dna::DNA::new("A").unwrap().into_rna()
67+
dna::Rna::new("U").unwrap(),
68+
dna::Dna::new("A").unwrap().into_rna()
6969
);
7070
}
7171

7272
#[test]
7373
#[ignore]
7474
fn test_transcribes_thymine_to_adenine() {
7575
assert_eq!(
76-
dna::RNA::new("A").unwrap(),
77-
dna::DNA::new("T").unwrap().into_rna()
76+
dna::Rna::new("A").unwrap(),
77+
dna::Dna::new("T").unwrap().into_rna()
7878
);
7979
}
8080

8181
#[test]
8282
#[ignore]
8383
fn test_transcribes_all_dna_to_rna() {
8484
assert_eq!(
85-
dna::RNA::new("UGCACCAGAAUU").unwrap(),
86-
dna::DNA::new("ACGTGGTCTTAA").unwrap().into_rna()
85+
dna::Rna::new("UGCACCAGAAUU").unwrap(),
86+
dna::Dna::new("ACGTGGTCTTAA").unwrap().into_rna()
8787
)
8888
}

0 commit comments

Comments
 (0)