2024-05-22 16:16:50 +03:00
|
|
|
// TODO: Fix the compiler error on this function.
|
2024-09-14 10:48:26 +03:00
|
|
|
fn picky_eater(food: &str) -> &str {
|
|
|
|
if food == "strawberry" {
|
|
|
|
"Yummy!"
|
2020-05-01 07:17:17 +03:00
|
|
|
} else {
|
|
|
|
1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-17 23:46:21 +03:00
|
|
|
fn main() {
|
|
|
|
// You can optionally experiment here.
|
|
|
|
}
|
|
|
|
|
2024-05-22 16:16:50 +03:00
|
|
|
// TODO: Read the tests to understand the desired behavior.
|
|
|
|
// Make all tests pass without changing them.
|
2020-05-01 07:17:17 +03:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
2024-09-14 10:48:26 +03:00
|
|
|
fn yummy_food() {
|
|
|
|
// This means that calling `picky_eater` with the argument "food" should return "Yummy!".
|
|
|
|
assert_eq!(picky_eater("strawberry"), "Yummy!");
|
2020-05-01 07:17:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2024-09-14 10:48:26 +03:00
|
|
|
fn neutral_food() {
|
|
|
|
assert_eq!(picky_eater("potato"), "I guess I can eat that.");
|
2020-05-01 07:17:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2024-09-14 10:48:26 +03:00
|
|
|
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!");
|
2020-05-01 07:17:17 +03:00
|
|
|
}
|
|
|
|
}
|