mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-25 14:57:32 -05:00
35 lines
756 B
Rust
35 lines
756 B
Rust
// TODO: Fix the compiler error on this function.
|
|
fn foo_if_fizz(fizzish: &str) -> &str {
|
|
if fizzish == "fizz" {
|
|
"foo"
|
|
} else {
|
|
1
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
// You can optionally experiment here.
|
|
}
|
|
|
|
// TODO: Read the tests to understand the desired behavior.
|
|
// Make all tests pass without changing them.
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn foo_for_fizz() {
|
|
// This means that calling `foo_if_fizz` with the argument "fizz" should return "foo".
|
|
assert_eq!(foo_if_fizz("fizz"), "foo");
|
|
}
|
|
|
|
#[test]
|
|
fn bar_for_fuzz() {
|
|
assert_eq!(foo_if_fizz("fuzz"), "bar");
|
|
}
|
|
|
|
#[test]
|
|
fn default_to_baz() {
|
|
assert_eq!(foo_if_fizz("literally anything"), "baz");
|
|
}
|
|
}
|