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