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