diff options
| author | mo8it <mo8it@proton.me> | 2024-05-22 15:16:50 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-05-22 15:16:50 +0200 |
| commit | eafb157d60ee46e95e2b54ec75b33180a838b0c5 (patch) | |
| tree | 9920ac8ace97ec72b19687af80283f4e5d0cb148 /solutions | |
| parent | 7cdf6b79429428e944b440eb713e711d844a92d7 (diff) | |
if2 solution
Diffstat (limited to 'solutions')
| -rw-r--r-- | solutions/03_if/if2.rs | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/solutions/03_if/if2.rs b/solutions/03_if/if2.rs index 4e18198..440bba0 100644 --- a/solutions/03_if/if2.rs +++ b/solutions/03_if/if2.rs @@ -1 +1,33 @@ -// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 +fn foo_if_fizz(fizzish: &str) -> &str { + if fizzish == "fizz" { + "foo" + } else if fizzish == "fuzz" { + "bar" + } else { + "baz" + } +} + +fn main() { + // You can optionally experiment here. +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn foo_for_fizz() { + assert_eq!(foo_if_fizz("fizz"), "foo"); + } + + #[test] + fn bar_for_fuzz() { + assert_eq!(foo_if_fizz("fuzz"), "bar"); + } + + #[test] + fn default_to_baz() { + assert_eq!(foo_if_fizz("literally anything"), "baz"); + } +} |
