17 lines
524 B
Rust
17 lines
524 B
Rust
use leetcode::longest_common_prefix::longest_common_prefix;
|
|
|
|
use test_case::test_case;
|
|
|
|
#[test_case(&["flow", "flower", "flight"], "fl"; "simple")]
|
|
#[test_case(&["dog", "doggo", "doggie"], "dog"; "shortest string")]
|
|
#[test_case(&["racecar", "car"], ""; "no common prefix")]
|
|
#[test_case(&[], ""; "empty")]
|
|
fn test_longest_common_prefix(input: &[&str], expected: &str) {
|
|
let input = input
|
|
.into_iter()
|
|
.map(ToString::to_string)
|
|
.collect::<Vec<String>>();
|
|
|
|
assert_eq!(longest_common_prefix(input), expected);
|
|
}
|