From 394aed28eef17cf9984675ac68a9e0a49a38c2b0 Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Wed, 21 Nov 2018 11:22:33 +0300 Subject: [PATCH] nucleotide-count: Updated the exercise to the 1.3.0 version Relevant PRs: - https://github.com/exercism/problem-specifications/pull/666 - https://github.com/exercism/problem-specifications/pull/951 - https://github.com/exercism/problem-specifications/pull/957 - https://github.com/exercism/problem-specifications/pull/1126 Basically renamed the old test cases and the process function. --- exercises/nucleotide-count/Cargo.toml | 2 +- .../tests/nucleotide-count.rs | 33 ++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/exercises/nucleotide-count/Cargo.toml b/exercises/nucleotide-count/Cargo.toml index 43ecd2d82..ae5eceadb 100644 --- a/exercises/nucleotide-count/Cargo.toml +++ b/exercises/nucleotide-count/Cargo.toml @@ -1,3 +1,3 @@ [package] name = "nucleotide-count" -version = "0.0.0" +version = "1.3.0" diff --git a/exercises/nucleotide-count/tests/nucleotide-count.rs b/exercises/nucleotide-count/tests/nucleotide-count.rs index d6eb47f76..403ae9c53 100644 --- a/exercises/nucleotide-count/tests/nucleotide-count.rs +++ b/exercises/nucleotide-count/tests/nucleotide-count.rs @@ -2,7 +2,7 @@ extern crate nucleotide_count as dna; use std::collections::HashMap; -fn check_dna(s: &str, pairs: &[(char, usize)]) { +fn process_nucleotidecounts_case(s: &str, pairs: &[(char, usize)]) { // The reason for the awkward code in here is to ensure that the failure // message for assert_eq! is as informative as possible. A simpler // solution would simply check the length of the map, and then @@ -11,6 +11,7 @@ fn check_dna(s: &str, pairs: &[(char, usize)]) { for &(k, v) in pairs.iter() { assert_eq!((k, m.remove(&k)), (k, Some(v))); } + // may fail with a message that clearly shows all extra pairs in the map assert_eq!(m.iter().collect::>(), vec![]); } @@ -58,22 +59,29 @@ fn counts_returns_result() { #[test] #[ignore] -fn test_nucleotide_count_empty() { - check_dna("", &[('A', 0), ('T', 0), ('C', 0), ('G', 0)]); +fn test_empty_strand() { + process_nucleotidecounts_case("", &[('A', 0), ('T', 0), ('C', 0), ('G', 0)]); +} + +#[test] +#[ignore] +/// can count one nucleotide in single-character input +fn test_can_count_one_nucleotide_in_singlecharacter_input() { + process_nucleotidecounts_case("G", &[('A', 0), ('C', 0), ('G', 1), ('T', 0)]); } #[test] #[ignore] -fn test_nucleotide_count_only_guanine() { - check_dna("GGGGGGGG", &[('A', 0), ('T', 0), ('C', 0), ('G', 8)]); +fn test_strand_with_repeated_nucleotide() { + process_nucleotidecounts_case("GGGGGGG", &[('A', 0), ('T', 0), ('C', 0), ('G', 7)]); } #[test] #[ignore] -fn test_nucleotide_count_counts_all() { - check_dna( - "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAA\ - GAGTGTCTGATAGCAGC", +/// strand with multiple nucleotides +fn test_strand_with_multiple_nucleotides() { + process_nucleotidecounts_case( + "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC", &[('A', 20), ('T', 21), ('C', 12), ('G', 17)], ); } @@ -83,3 +91,10 @@ fn test_nucleotide_count_counts_all() { fn counts_invalid_nucleotide_results_in_err() { assert_eq!(dna::nucleotide_counts("GGXXX"), Err('X')); } + +#[test] +#[ignore] +/// strand with invalid nucleotides +fn test_strand_with_invalid_nucleotides() { + assert_eq!(dna::nucleotide_counts("AGXXACT"), Err('X'),); +}