rustlings/exercises/03_if/if2.rs

36 lines
756 B
Rust
Raw Normal View History

2024-05-22 16:16:50 +03:00
// TODO: Fix the compiler error on this function.
2024-05-22 16:04:12 +03:00
fn foo_if_fizz(fizzish: &str) -> &str {
2020-05-01 07:17:17 +03:00
if fizzish == "fizz" {
"foo"
} else {
1
}
}
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]
fn foo_for_fizz() {
2024-05-22 16:16:50 +03:00
// This means that calling `foo_if_fizz` with the argument "fizz" should return "foo".
2024-05-22 16:13:18 +03:00
assert_eq!(foo_if_fizz("fizz"), "foo");
2020-05-01 07:17:17 +03:00
}
#[test]
fn bar_for_fuzz() {
2024-05-22 16:13:18 +03:00
assert_eq!(foo_if_fizz("fuzz"), "bar");
2020-05-01 07:17:17 +03:00
}
#[test]
fn default_to_baz() {
2024-05-22 16:13:18 +03:00
assert_eq!(foo_if_fizz("literally anything"), "baz");
2020-05-01 07:17:17 +03:00
}
}