2024-05-22 09:54:35 -04:00
|
|
|
fn animal_habitat(animal: &str) -> &str {
|
|
|
|
// TODO: Fix the compiler error in the statement below.
|
2023-07-03 14:52:13 -04:00
|
|
|
let identifier = if animal == "crab" {
|
|
|
|
1
|
|
|
|
} else if animal == "gopher" {
|
|
|
|
2.0
|
|
|
|
} else if animal == "snake" {
|
|
|
|
3
|
|
|
|
} else {
|
|
|
|
"Unknown"
|
|
|
|
};
|
|
|
|
|
2024-05-22 09:54:35 -04:00
|
|
|
// Don't change the expression below!
|
|
|
|
if identifier == 1 {
|
2023-07-03 14:52:13 -04:00
|
|
|
"Beach"
|
|
|
|
} else if identifier == 2 {
|
|
|
|
"Burrow"
|
|
|
|
} else if identifier == 3 {
|
|
|
|
"Desert"
|
|
|
|
} else {
|
|
|
|
"Unknown"
|
2024-05-22 09:54:35 -04:00
|
|
|
}
|
2023-07-03 14:52:13 -04:00
|
|
|
}
|
2023-09-04 07:53:54 -04:00
|
|
|
|
2024-04-17 16:46:21 -04:00
|
|
|
fn main() {
|
|
|
|
// You can optionally experiment here.
|
|
|
|
}
|
|
|
|
|
2024-05-22 09:54:35 -04:00
|
|
|
// Don't change the tests!
|
2023-07-03 14:52:13 -04:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn gopher_lives_in_burrow() {
|
2024-05-22 09:54:35 -04:00
|
|
|
assert_eq!(animal_habitat("gopher"), "Burrow")
|
2023-07-03 14:52:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn snake_lives_in_desert() {
|
2024-05-22 09:54:35 -04:00
|
|
|
assert_eq!(animal_habitat("snake"), "Desert")
|
2023-07-03 14:52:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn crab_lives_on_beach() {
|
2024-05-22 09:54:35 -04:00
|
|
|
assert_eq!(animal_habitat("crab"), "Beach")
|
2023-07-03 14:52:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unknown_animal() {
|
2024-05-22 09:54:35 -04:00
|
|
|
assert_eq!(animal_habitat("dinosaur"), "Unknown")
|
2023-07-03 14:52:13 -04:00
|
|
|
}
|
|
|
|
}
|