1
0
Fork 0
mirror of https://github.com/notohh/rustlings.git synced 2024-12-22 00:18:09 -05:00
rustlings/exercises/03_if/if2.rs

36 lines
756 B
Rust
Raw Normal View History

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