Created
September 24, 2021 19:24
-
-
Save Blazing-Mike/522a552efb21db332d9b84155ff40471 to your computer and use it in GitHub Desktop.
function and if statement i wrote in my rustlings exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let answer = square(10); | |
println!("The answer is {}", answer); | |
} | |
fn square(num: i32) -> i32 { | |
num * num | |
} | |
pub fn fizz_if_foo(fizzish: &str) -> &str { | |
if fizzish == "fizz" { | |
"foo" | |
} else if fizzish == "fuzz" { | |
"bar" | |
} else { | |
"baz" | |
} | |
} | |
// No test changes needed! | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
#[test] | |
fn foo_for_fizz() { | |
assert_eq!(fizz_if_foo("fizz"), "foo") | |
} | |
#[test] | |
fn bar_for_fuzz() { | |
assert_eq!(fizz_if_foo("fuzz"), "bar") | |
} | |
#[test] | |
fn default_to_baz() { | |
assert_eq!(fizz_if_foo("literally anything"), "baz") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment