Skip to content

Commit

Permalink
Test naughty_word function, make it take a slice and not a Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
sondr3 committed Oct 14, 2018
1 parent 03e8d81 commit ebc19cd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,22 @@ fn main() -> Result<(), Box<std::error::Error>> {
Ok(())
}

fn naughty_word(word: &str, naughty_list: &Vec<&str>) -> bool {
fn naughty_word(word: &str, naughty_list: &[&str]) -> bool {
if naughty_list.contains(&word) {
return true;
}
false
}

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

#[test]
fn test_naughty_words() {
let curses: Vec<&str> = CURSES.lines().collect();
assert!(naughty_word("fuck", &curses));
assert!(naughty_word("cyberfuckers", &curses));
assert!(!naughty_word("pretty", &curses));
}
}

0 comments on commit ebc19cd

Please sign in to comment.