File tree Expand file tree Collapse file tree 1 file changed +13
-21
lines changed
exercises/06_ticket_management/11_mutable_slices/src Expand file tree Collapse file tree 1 file changed +13
-21
lines changed Original file line number Diff line number Diff line change 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.
4
3
5
4
#[ cfg( test) ]
6
5
mod tests {
7
6
use super :: * ;
8
7
9
8
#[ test]
10
9
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! [ ] ) ;
14
13
}
15
14
16
15
#[ 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 ] ) ;
21
20
}
22
21
23
22
#[ 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 ] ) ;
35
27
}
36
28
}
You can’t perform that action at this time.
0 commit comments