minigrep_fun_test 0.1.0

An application to grep a word with some funny utilities
Documentation
fn count_word_in_line(line: &str) -> u32 {
    let splitted_words: Vec<&str> = line.split_whitespace().collect();
    splitted_words.len() as u32
}

pub fn count_word_in_lines(lines: &Vec<&str>) -> u32 {
    lines.iter().map(|&line| count_word_in_line(line)).sum()
}

pub fn except_word_in_line(except_word: &str, line: &str) -> String {
    let splitted_words: Vec<&str> = line
        .split_whitespace()
        .filter(|&word| word.ne(except_word))
        .collect();

    splitted_words.join(" ")
}

pub fn except_word_in_lines<'a>(except_word: &str, lines: &Vec<&'a str>) -> Vec<String> {
    lines
        .iter()
        .map(|&line| except_word_in_line(except_word, line))
        .collect()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn count_word_in_line_test() {
        let line = "Hello Doggo";

        assert_eq!(2, count_word_in_line(&line));
    }

    #[test]
    fn count_word_in_lines_test() {
        let lines = vec!["Hello doggo", "Slave", "doggo"];

        assert_eq!(4, count_word_in_lines(&lines));
    }

    #[test]
    fn except_word_in_line_test() {
        let line = "Good morning doggo";

        assert_eq!(
            "Good morning",
            except_word_in_line("doggo", line)
        );
    }

    #[test]
    fn except_word_in_lines_test() {
        let lines = vec!["Hello doggo", "Slave", "doggo"];

        assert_eq!(vec!["Hello", "Slave"], except_word_in_lines("doggo", &lines));
    }
}