From eafb157d60ee46e95e2b54ec75b33180a838b0c5 Mon Sep 17 00:00:00 2001 From: mo8it Date: Wed, 22 May 2024 15:16:50 +0200 Subject: if2 solution --- solutions/03_if/if2.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'solutions') 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"); + } +} -- cgit v1.2.3