aboutsummaryrefslogtreecommitdiff
path: root/rust/rna-transcription/tests/rna-transcription.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/rna-transcription/tests/rna-transcription.rs')
-rw-r--r--rust/rna-transcription/tests/rna-transcription.rs79
1 files changed, 79 insertions, 0 deletions
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 @@
1use rna_transcription as dna;
2
3#[test]
4fn test_valid_dna_input() {
5 assert!(dna::Dna::new("GCTA").is_ok());
6}
7
8#[test]
9fn test_valid_rna_input() {
10 assert!(dna::Rna::new("CGAU").is_ok());
11}
12
13#[test]
14fn test_invalid_dna_input() {
15 // Invalid character
16 assert_eq!(dna::Dna::new("X").err(), Some(0));
17 // Valid nucleotide, but invalid in context
18 assert_eq!(dna::Dna::new("U").err(), Some(0));
19 // Longer string with contained errors
20 assert_eq!(dna::Dna::new("ACGTUXXCTTAA").err(), Some(4));
21}
22
23#[test]
24fn test_invalid_rna_input() {
25 // Invalid character
26 assert_eq!(dna::Rna::new("X").unwrap_err(), 0);
27 // Valid nucleotide, but invalid in context
28 assert_eq!(dna::Rna::new("T").unwrap_err(), 0);
29 // Longer string with contained errors
30 assert_eq!(dna::Rna::new("ACGUTTXCUUAA").unwrap_err(), 4);
31}
32
33#[test]
34fn test_acid_equals_acid() {
35 assert_eq!(dna::Dna::new("CGA").unwrap(), dna::Dna::new("CGA").unwrap());
36 assert_ne!(dna::Dna::new("CGA").unwrap(), dna::Dna::new("AGC").unwrap());
37 assert_eq!(dna::Rna::new("CGA").unwrap(), dna::Rna::new("CGA").unwrap());
38 assert_ne!(dna::Rna::new("CGA").unwrap(), dna::Rna::new("AGC").unwrap());
39}
40
41#[test]
42fn test_transcribes_cytosine_guanine() {
43 assert_eq!(
44 dna::Rna::new("G").unwrap(),
45 dna::Dna::new("C").unwrap().into_rna()
46 );
47}
48
49#[test]
50fn test_transcribes_guanine_cytosine() {
51 assert_eq!(
52 dna::Rna::new("C").unwrap(),
53 dna::Dna::new("G").unwrap().into_rna()
54 );
55}
56
57#[test]
58fn test_transcribes_adenine_uracil() {
59 assert_eq!(
60 dna::Rna::new("U").unwrap(),
61 dna::Dna::new("A").unwrap().into_rna()
62 );
63}
64
65#[test]
66fn test_transcribes_thymine_to_adenine() {
67 assert_eq!(
68 dna::Rna::new("A").unwrap(),
69 dna::Dna::new("T").unwrap().into_rna()
70 );
71}
72
73#[test]
74fn test_transcribes_all_dna_to_rna() {
75 assert_eq!(
76 dna::Rna::new("UGCACCAGAAUU").unwrap(),
77 dna::Dna::new("ACGTGGTCTTAA").unwrap().into_rna()
78 )
79}