diff options
| author | mo8it <mo8it@proton.me> | 2024-06-26 02:25:59 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-06-26 02:25:59 +0200 |
| commit | 29bcb282dacead96df6e6cdbec9ac1ba8008d90f (patch) | |
| tree | ad23531134275ffea1a29095ac5b4e8f384b82c2 /exercises | |
| parent | f1bd4447924e797e8fb0012f6bc47a507438f3f5 (diff) | |
quiz2 solution
Diffstat (limited to 'exercises')
| -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", + ] + ); } } |
