I have a function that generates anagrams and I want to test it so I have the following:
pub fn group_anagrams(strs: Vec<String>) -> Vec<Vec<String>> {
unimplemented!()
}
fn main() {
let words = [
"eat".to_string(),
"tea".to_string(),
"tan".to_string(),
"ate".to_string(),
"nat".to_string(),
"bat".to_string(),
]
.to_vec();
let answer = [["ate", "eat", "tea"], ["nat", "tan"], ["bat"]];
let solution = group_anagrams(words);
assert_eq!(answer, solution);
}
I can't figure out how to write this in a way that will compile:
error[E0308]: mismatched types
--> src/main.rs:15:42
|
15 | let answer = [["ate", "eat", "tea"], ["nat", "tan"], ["bat"]];
| ^^^^^^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements
|
= note: expected type `[&str; 3]`
found array `[&str; 2]`