-// TODO: Define a function named `lowercase` that converts all characters in a string to lowercase,
-// modifying the input in place.
-// Does it need to take a `&mut String`? Does a `&mut str` work? Why or why not?
+// TODO: Define a function named `squared` that raises all `i32`s within a slice to the power of 2.
+// The slice should be modified in place.
#[cfg(test)]
mod tests {
#[test]
fn empty() {
- let mut s = String::from("");
- lowercase(&mut s);
- assert_eq!(s, "");
+ let mut s = vec![];
+ squared(&mut s);
+ assert_eq!(s, vec![]);
}
#[test]
- fn one_char() {
- let mut s = String::from("A");
- lowercase(&mut s);
- assert_eq!(s, "a");
+ fn one() {
+ let mut s = [2];
+ squared(&mut s);
+ assert_eq!(s, [4]);
}
#[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!");
+ fn multiple() {
+ let mut s = vec![2, 4];
+ squared(&mut s);
+ assert_eq!(s, vec![4, 16]);
}
}