Sha256: ebc03616944ec71bd08291e491ff2436fef0a7dde8d25de40db7dcc442bd82f9

Contents?: true

Size: 1.48 KB

Versions: 59

Compression:

Stored size: 1.48 KB

Contents

extern crate nucleotide_count as dna;

use std::collections::HashMap;

fn check_dna(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
    // check for the presence and value of each key in the given pairs vector.
    let mut m: HashMap<char, usize> = dna::nucleotide_counts(s);
    for &(k, v) in pairs.iter() {
        assert_eq!((k, m.remove(&k).unwrap()), (k, v));
    }
    // may fail with a message that clearly shows all extra pairs in the map
    assert_eq!(m.iter().collect::<Vec<(&char,&usize)>>(), vec!());
}

#[test]
fn test_count_empty() {
    assert_eq!(dna::count('A', ""), 0);
}

#[test]
#[ignore]
fn test_count_repetitive_cytosine() {
    assert_eq!(dna::count('C', "CCCCC"), 5);
}

#[test]
#[ignore]
fn test_count_only_thymine() {
    assert_eq!(dna::count('T', "GGGGGTAACCCGG"), 1);
}

#[test]
#[ignore]
fn test_nucleotide_count_empty() {
    check_dna(
        "",
        &[('A', 0), ('T', 0), ('C', 0), ('G', 0)]);
}

#[test]
#[ignore]
fn test_nucleotide_count_only_guanine() {
    check_dna(
        "GGGGGGGG",
        &[('A', 0), ('T', 0), ('C', 0), ('G', 8)]);
}

#[test]
#[ignore]
fn test_nucleotide_count_counts_all() {
    check_dna(
        "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAA\
         GAGTGTCTGATAGCAGC",
        &[('A', 20), ('T', 21), ('C', 12), ('G', 17)]);
}

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
trackler-2.0.5.2 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.5.1 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.5.0 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.4.0 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.3.9 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.3.8 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.3.7 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.3.6 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.3.5 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.3.4 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.3.3 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.3.2 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.3.1 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.3.0 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.2.0 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.1.2 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.1.1 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.1.0 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.0.10 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs
trackler-2.0.0.9 tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs