mirror of
https://github.com/notohh/rustlings.git
synced 2024-12-18 06:58:10 -05:00
b540c6df25
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.
35 lines
750 B
Rust
35 lines
750 B
Rust
fn picky_eater(food: &str) -> &str {
|
|
if food == "strawberry" {
|
|
"Yummy!"
|
|
} else if food == "potato" {
|
|
"I guess I can eat that."
|
|
} else {
|
|
"No thanks!"
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
// You can optionally experiment here.
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn yummy_food() {
|
|
assert_eq!(picky_eater("strawberry"), "Yummy!");
|
|
}
|
|
|
|
#[test]
|
|
fn neutral_food() {
|
|
assert_eq!(picky_eater("potato"), "I guess I can eat that.");
|
|
}
|
|
|
|
#[test]
|
|
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!");
|
|
}
|
|
}
|