Skip to content

Commit 51aab47

Browse files
authored
Merge pull request #763 from ZapAnton/update_nucleotide_count
nucleotide-count: Updated the exercise to the 1.3.0 version
2 parents 8bc3d7d + 394aed2 commit 51aab47

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

exercises/nucleotide-count/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[package]
22
name = "nucleotide-count"
3-
version = "0.0.0"
3+
version = "1.3.0"

exercises/nucleotide-count/tests/nucleotide-count.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate nucleotide_count as dna;
22

33
use std::collections::HashMap;
44

5-
fn check_dna(s: &str, pairs: &[(char, usize)]) {
5+
fn process_nucleotidecounts_case(s: &str, pairs: &[(char, usize)]) {
66
// The reason for the awkward code in here is to ensure that the failure
77
// message for assert_eq! is as informative as possible. A simpler
88
// solution would simply check the length of the map, and then
@@ -11,6 +11,7 @@ fn check_dna(s: &str, pairs: &[(char, usize)]) {
1111
for &(k, v) in pairs.iter() {
1212
assert_eq!((k, m.remove(&k)), (k, Some(v)));
1313
}
14+
1415
// may fail with a message that clearly shows all extra pairs in the map
1516
assert_eq!(m.iter().collect::<Vec<(&char, &usize)>>(), vec![]);
1617
}
@@ -58,22 +59,29 @@ fn counts_returns_result() {
5859

5960
#[test]
6061
#[ignore]
61-
fn test_nucleotide_count_empty() {
62-
check_dna("", &[('A', 0), ('T', 0), ('C', 0), ('G', 0)]);
62+
fn test_empty_strand() {
63+
process_nucleotidecounts_case("", &[('A', 0), ('T', 0), ('C', 0), ('G', 0)]);
64+
}
65+
66+
#[test]
67+
#[ignore]
68+
/// can count one nucleotide in single-character input
69+
fn test_can_count_one_nucleotide_in_singlecharacter_input() {
70+
process_nucleotidecounts_case("G", &[('A', 0), ('C', 0), ('G', 1), ('T', 0)]);
6371
}
6472

6573
#[test]
6674
#[ignore]
67-
fn test_nucleotide_count_only_guanine() {
68-
check_dna("GGGGGGGG", &[('A', 0), ('T', 0), ('C', 0), ('G', 8)]);
75+
fn test_strand_with_repeated_nucleotide() {
76+
process_nucleotidecounts_case("GGGGGGG", &[('A', 0), ('T', 0), ('C', 0), ('G', 7)]);
6977
}
7078

7179
#[test]
7280
#[ignore]
73-
fn test_nucleotide_count_counts_all() {
74-
check_dna(
75-
"AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAA\
76-
GAGTGTCTGATAGCAGC",
81+
/// strand with multiple nucleotides
82+
fn test_strand_with_multiple_nucleotides() {
83+
process_nucleotidecounts_case(
84+
"AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC",
7785
&[('A', 20), ('T', 21), ('C', 12), ('G', 17)],
7886
);
7987
}
@@ -83,3 +91,10 @@ fn test_nucleotide_count_counts_all() {
8391
fn counts_invalid_nucleotide_results_in_err() {
8492
assert_eq!(dna::nucleotide_counts("GGXXX"), Err('X'));
8593
}
94+
95+
#[test]
96+
#[ignore]
97+
/// strand with invalid nucleotides
98+
fn test_strand_with_invalid_nucleotides() {
99+
assert_eq!(dna::nucleotide_counts("AGXXACT"), Err('X'),);
100+
}

0 commit comments

Comments
 (0)