Sha256: d0af658b2c6ccff6615d7aa5507edcda9f20043ac7449b69195e665c12b4c787

Contents?: true

Size: 1.75 KB

Versions: 57

Compression:

Stored size: 1.75 KB

Contents

use std::collections::HashMap;

extern crate word_count;

fn check_word_count(s: &str, pairs: &[(&str, u32)]) {
    // 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<String, u32> = word_count::word_count(s);
    for &(k, v) in pairs.iter() {
        assert_eq!((k, m.remove(&k.to_string()).unwrap_or(0)), (k, v));
    }
    // may fail with a message that clearly shows all extra pairs in the map
    assert_eq!(m.iter().collect::<Vec<(&String,&u32)>>(), vec!());
}

#[test]
fn test_count_one_word() {
    check_word_count("word", &[("word", 1)]);
}

#[test]
#[ignore]
fn test_count_one_of_each() {
    check_word_count(
        "one of each",
        &[("one", 1),
          ("of", 1),
          ("each", 1)]);
}

#[test]
#[ignore]
fn test_count_multiple_occurrences() {
    check_word_count(
        "one fish two fish red fish blue fish",
        &[("one", 1),
          ("fish", 4),
          ("two", 1),
          ("red", 1),
          ("blue", 1)]);
}

#[test]
#[ignore]
fn test_ignore_punctuation() {
    check_word_count(
        "car : carpet as java : javascript!!&@$%^&",
        &[("car", 1),
          ("carpet", 1),
          ("as", 1),
          ("java", 1),
          ("javascript", 1)]);
}

#[test]
#[ignore]
fn test_include_numbers() {
    check_word_count(
        "testing, 1, 2 testing",
        &[("testing", 2),
          ("1", 1),
          ("2", 1)]);
}

#[test]
#[ignore]
fn test_normalize_case() {
    check_word_count(
        "go Go GO Stop stop",
        &[("go", 3),
          ("stop", 2)]);
}

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
trackler-2.2.1.171 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.170 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.169 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.167 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.166 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.165 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.164 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.163 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.162 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.161 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.160 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.159 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.158 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.157 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.156 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.155 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.154 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.153 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.152 tracks/rust/exercises/word-count/tests/word-count.rs
trackler-2.2.1.151 tracks/rust/exercises/word-count/tests/word-count.rs