Skip to content

Instantly share code, notes, and snippets.

@Blazing-Mike
Created September 24, 2021 19:24
Show Gist options
  • Save Blazing-Mike/522a552efb21db332d9b84155ff40471 to your computer and use it in GitHub Desktop.
Save Blazing-Mike/522a552efb21db332d9b84155ff40471 to your computer and use it in GitHub Desktop.
function and if statement i wrote in my rustlings exercise
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