Skip to content

Commit

Permalink
Finish to read ch10
Browse files Browse the repository at this point in the history
  • Loading branch information
denjiry committed Dec 14, 2019
1 parent 5928530 commit a19fd88
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ch10/wcount/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,37 @@ fn word_count_works2() {

assert_eq!(count(Cursor::new("aa cc dd"), CountOption::Word), exp);
}
#[cfg(test)]
mod test {
use super::*;
use std::io::Cursor;

macro_rules! assert_map {
($expr: expr, {$($key: expr => $value:expr),*}) => {
$(assert_eq!($expr[$key], $value));*
};
}

#[test]
fn word_count_works3() {
let freqs = count(Cursor::new("aa cc dd"), CountOption::Word);

assert_eq!(freqs.len(), 3);
assert_map!(freqs, {"aa" => 1, "cc" => 1, "dd" => 1});
}
}

#[test]
#[should_panic]
fn word_count_do_not_contain_unknown_words() {
use std::io::Cursor;

count(
Cursor::new([
b'a', // a
0xf0, 0x90, 0x80, // でたらめなバイト列
0xe3, 0x81, 0x82, // あ
]),
CountOption::Word,
);
}

0 comments on commit a19fd88

Please sign in to comment.