2024-05-13 04:21:03 +08:00
|
|
|
// TODO: Define a function named `lowercase` that converts all characters in a string to lowercase,
|
|
|
|
// modifying the input in place.
|
2024-06-20 16:18:55 +08:00
|
|
|
// Does it need to take a `&mut String`? Does a `&mut str` work? Why or why not?
|
2024-05-13 04:21:03 +08:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn empty() {
|
|
|
|
let mut s = String::from("");
|
|
|
|
lowercase(&mut s);
|
|
|
|
assert_eq!(s, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn one_char() {
|
|
|
|
let mut s = String::from("A");
|
|
|
|
lowercase(&mut s);
|
|
|
|
assert_eq!(s, "a");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multiple_chars() {
|
|
|
|
let mut s = String::from("Hello, World!");
|
|
|
|
lowercase(&mut s);
|
|
|
|
assert_eq!(s, "hello, world!");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mut_slice() {
|
|
|
|
let mut s = "Hello, World!".to_string();
|
|
|
|
lowercase(s.as_mut_str());
|
|
|
|
assert_eq!(s, "hello, world!");
|
|
|
|
}
|
|
|
|
}
|