diff options
Diffstat (limited to 'exercises/quizzes/quiz2.rs')
| -rw-r--r-- | exercises/quizzes/quiz2.rs | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/exercises/quizzes/quiz2.rs b/exercises/quizzes/quiz2.rs index e01e3f1..fd6bc77 100644 --- a/exercises/quizzes/quiz2.rs +++ b/exercises/quizzes/quiz2.rs @@ -11,10 +11,11 @@ // - Uppercase the string // - Trim the string // - Append "bar" to the string a specified amount of times +// // The exact form of this will be: -// - The input is going to be a Vector of a 2-length tuple, +// - The input is going to be a vector of a 2-length tuple, // the first element is the string, the second one is the command. -// - The output element is going to be a Vector of strings. +// - The output element is going to be a vector of strings. enum Command { Uppercase, @@ -25,15 +26,8 @@ enum Command { mod my_module { use super::Command; - // TODO: Complete the function signature! - pub fn transformer(input: ???) -> ??? { - // TODO: Complete the output declaration! - let mut output: ??? = vec![]; - for (string, command) in input.iter() { - // TODO: Complete the function body. You can do it! - } - output - } + // TODO: Complete the function. + // pub fn transformer(input: ???) -> ??? { ??? } } fn main() { @@ -43,20 +37,27 @@ fn main() { #[cfg(test)] mod tests { // TODO: What do we need to import to have `transformer` in scope? - use ???; + // use ???; use super::Command; #[test] fn it_works() { - let output = transformer(vec![ - ("hello".into(), Command::Uppercase), - (" all roads lead to rome! ".into(), Command::Trim), - ("foo".into(), Command::Append(1)), - ("bar".into(), Command::Append(5)), - ]); - assert_eq!(output[0], "HELLO"); - assert_eq!(output[1], "all roads lead to rome!"); - assert_eq!(output[2], "foobar"); - assert_eq!(output[3], "barbarbarbarbarbar"); + let input = vec![ + ("hello".to_string(), Command::Uppercase), + (" all roads lead to rome! ".to_string(), Command::Trim), + ("foo".to_string(), Command::Append(1)), + ("bar".to_string(), Command::Append(5)), + ]; + let output = transformer(input); + + assert_eq!( + output, + [ + "HELLO", + "all roads lead to rome!", + "foobar", + "barbarbarbarbarbar", + ] + ); } } |
