Skip to content

Commit 526b81e

Browse files
Change exercise for mutable slices. Closes mainmatter#26
1 parent 45236a2 commit 526b81e

File tree

1 file changed

+13
-21
lines changed
  • exercises/06_ticket_management/11_mutable_slices/src

1 file changed

+13
-21
lines changed
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
1-
// TODO: Define a function named `lowercase` that converts all characters in a string to lowercase,
2-
// modifying the input in place.
3-
// Does it need to take a `&mut String`? Does a `&mut str` work? Why or why not?
1+
// TODO: Define a function named `squared` that raises all `i32`s within a slice to the power of 2.
2+
// The slice should be modified in place.
43

54
#[cfg(test)]
65
mod tests {
76
use super::*;
87

98
#[test]
109
fn empty() {
11-
let mut s = String::from("");
12-
lowercase(&mut s);
13-
assert_eq!(s, "");
10+
let mut s = vec![];
11+
squared(&mut s);
12+
assert_eq!(s, vec![]);
1413
}
1514

1615
#[test]
17-
fn one_char() {
18-
let mut s = String::from("A");
19-
lowercase(&mut s);
20-
assert_eq!(s, "a");
16+
fn one() {
17+
let mut s = [2];
18+
squared(&mut s);
19+
assert_eq!(s, [4]);
2120
}
2221

2322
#[test]
24-
fn multiple_chars() {
25-
let mut s = String::from("Hello, World!");
26-
lowercase(&mut s);
27-
assert_eq!(s, "hello, world!");
28-
}
29-
30-
#[test]
31-
fn mut_slice() {
32-
let mut s = "Hello, World!".to_string();
33-
lowercase(s.as_mut_str());
34-
assert_eq!(s, "hello, world!");
23+
fn multiple() {
24+
let mut s = vec![2, 4];
25+
squared(&mut s);
26+
assert_eq!(s, vec![4, 16]);
3527
}
3628
}

0 commit comments

Comments
 (0)