diff options
| author | Mo <76752051+mo8it@users.noreply.github.com> | 2024-09-16 12:54:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-16 12:54:20 +0200 |
| commit | 2894f3c45c650172beaf2faaf43b190834a3538e (patch) | |
| tree | cea6cff5ba2f33fd3042bb825a6fc814af809fbc /solutions/03_if/if2.rs | |
| parent | 1bae2dcb0019d579cdfe5a0c68a9e46780eea6dd (diff) | |
| parent | b540c6df253c1f528486bf4245da8eec66710684 (diff) | |
Merge pull request #2110 from senekor/remo/skkynvtqxkoz
Make if2 less confusing
Diffstat (limited to 'solutions/03_if/if2.rs')
| -rw-r--r-- | solutions/03_if/if2.rs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/solutions/03_if/if2.rs b/solutions/03_if/if2.rs index 440bba0..21c0dcd 100644 --- a/solutions/03_if/if2.rs +++ b/solutions/03_if/if2.rs @@ -1,10 +1,10 @@ -fn foo_if_fizz(fizzish: &str) -> &str { - if fizzish == "fizz" { - "foo" - } else if fizzish == "fuzz" { - "bar" +fn picky_eater(food: &str) -> &str { + if food == "strawberry" { + "Yummy!" + } else if food == "potato" { + "I guess I can eat that." } else { - "baz" + "No thanks!" } } @@ -17,17 +17,19 @@ mod tests { use super::*; #[test] - fn foo_for_fizz() { - assert_eq!(foo_if_fizz("fizz"), "foo"); + fn yummy_food() { + assert_eq!(picky_eater("strawberry"), "Yummy!"); } #[test] - fn bar_for_fuzz() { - assert_eq!(foo_if_fizz("fuzz"), "bar"); + fn neutral_food() { + assert_eq!(picky_eater("potato"), "I guess I can eat that."); } #[test] - fn default_to_baz() { - assert_eq!(foo_if_fizz("literally anything"), "baz"); + fn default_disliked_food() { + assert_eq!(picky_eater("broccoli"), "No thanks!"); + assert_eq!(picky_eater("gummy bears"), "No thanks!"); + assert_eq!(picky_eater("literally anything"), "No thanks!"); } } |
