Skip to content

Commit b540c6d

Browse files
committed
Make if2 less confusing
Some people would get stuck on this exercise, trying to understand the meaning behind foo, fuzz, baz etc. Making the theme of the code make a little more sense to humans should hopefully prevent people from getting confused by abstract and non-sensical tests.
1 parent 47f8a0c commit b540c6d

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

exercises/03_if/if2.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// TODO: Fix the compiler error on this function.
2-
fn foo_if_fizz(fizzish: &str) -> &str {
3-
if fizzish == "fizz" {
4-
"foo"
2+
fn picky_eater(food: &str) -> &str {
3+
if food == "strawberry" {
4+
"Yummy!"
55
} else {
66
1
77
}
@@ -18,18 +18,20 @@ mod tests {
1818
use super::*;
1919

2020
#[test]
21-
fn foo_for_fizz() {
22-
// This means that calling `foo_if_fizz` with the argument "fizz" should return "foo".
23-
assert_eq!(foo_if_fizz("fizz"), "foo");
21+
fn yummy_food() {
22+
// This means that calling `picky_eater` with the argument "food" should return "Yummy!".
23+
assert_eq!(picky_eater("strawberry"), "Yummy!");
2424
}
2525

2626
#[test]
27-
fn bar_for_fuzz() {
28-
assert_eq!(foo_if_fizz("fuzz"), "bar");
27+
fn neutral_food() {
28+
assert_eq!(picky_eater("potato"), "I guess I can eat that.");
2929
}
3030

3131
#[test]
32-
fn default_to_baz() {
33-
assert_eq!(foo_if_fizz("literally anything"), "baz");
32+
fn default_disliked_food() {
33+
assert_eq!(picky_eater("broccoli"), "No thanks!");
34+
assert_eq!(picky_eater("gummy bears"), "No thanks!");
35+
assert_eq!(picky_eater("literally anything"), "No thanks!");
3436
}
3537
}

solutions/03_if/if2.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
fn foo_if_fizz(fizzish: &str) -> &str {
2-
if fizzish == "fizz" {
3-
"foo"
4-
} else if fizzish == "fuzz" {
5-
"bar"
1+
fn picky_eater(food: &str) -> &str {
2+
if food == "strawberry" {
3+
"Yummy!"
4+
} else if food == "potato" {
5+
"I guess I can eat that."
66
} else {
7-
"baz"
7+
"No thanks!"
88
}
99
}
1010

@@ -17,17 +17,19 @@ mod tests {
1717
use super::*;
1818

1919
#[test]
20-
fn foo_for_fizz() {
21-
assert_eq!(foo_if_fizz("fizz"), "foo");
20+
fn yummy_food() {
21+
assert_eq!(picky_eater("strawberry"), "Yummy!");
2222
}
2323

2424
#[test]
25-
fn bar_for_fuzz() {
26-
assert_eq!(foo_if_fizz("fuzz"), "bar");
25+
fn neutral_food() {
26+
assert_eq!(picky_eater("potato"), "I guess I can eat that.");
2727
}
2828

2929
#[test]
30-
fn default_to_baz() {
31-
assert_eq!(foo_if_fizz("literally anything"), "baz");
30+
fn default_disliked_food() {
31+
assert_eq!(picky_eater("broccoli"), "No thanks!");
32+
assert_eq!(picky_eater("gummy bears"), "No thanks!");
33+
assert_eq!(picky_eater("literally anything"), "No thanks!");
3234
}
3335
}

0 commit comments

Comments
 (0)