Add word checking

This commit is contained in:
Joel Therrien 2023-07-30 13:00:01 -07:00
parent 37fe5bac56
commit 3c9a0db3cb

View file

@ -143,9 +143,8 @@ impl Dictionary for HashMap<String, f64> {
}
fn is_word_valid(&self, word: &Word) -> bool {
todo!()
let text = word.to_string();
self.contains_key(&text)
}
}
@ -813,6 +812,7 @@ mod tests {
board.get_cell_mut(Coordinates(6, 0)).unwrap().value = Some(Letter::new_fixed('L', 1));
fn check_board(board: &mut Board, inverted: bool) {
let dictionary = HashMap::create("resources/dictionary.csv");
println!("{}", board);
let words = board.find_played_words();
match words {
@ -820,6 +820,7 @@ mod tests {
assert_eq!(x.len(), 1);
let word = x.get(0).unwrap();
assert_eq!(word.to_string(), "JOEL");
assert!(!dictionary.is_word_valid(word));
assert_eq!(word.calculate_score(), 8 + 1 + 2 + 1);
}
@ -852,6 +853,7 @@ mod tests {
assert_eq!(x.to_string(), "EGG");
assert_eq!(x.calculate_score(), 2 + 2 + 2);
assert!(dictionary.is_word_valid(&x));
}
}
@ -863,10 +865,12 @@ mod tests {
let word = x.get(0).unwrap();
assert_eq!(word.to_string(), "EGG");
assert_eq!(word.calculate_score(), 2 + 2 + 2);
assert!(dictionary.is_word_valid(word));
let word = x.get(1).unwrap();
assert_eq!(word.to_string(), "JOEL");
assert_eq!(word.calculate_score(), 8 + 1 + 2 + 1);
assert!(!dictionary.is_word_valid(word));
}
Err(e) => { panic!("Expected to find a word to play; found error {}", e) }
}