summaryrefslogtreecommitdiff
path: root/solutions/03_if/if2.rs
diff options
context:
space:
mode:
Diffstat (limited to 'solutions/03_if/if2.rs')
-rw-r--r--solutions/03_if/if2.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/solutions/03_if/if2.rs b/solutions/03_if/if2.rs
new file mode 100644
index 0000000..440bba0
--- /dev/null
+++ b/solutions/03_if/if2.rs
@@ -0,0 +1,33 @@
+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");
+ }
+}