1
Fork 0
leetcode/tests/longest_common_prefix.rs

17 lines
524 B
Rust
Raw Normal View History

2022-04-08 20:53:04 +00:00
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);
}