Skip to content

Instantly share code, notes, and snippets.

Created October 30, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/a546e07484d09932eb8e to your computer and use it in GitHub Desktop.
Save anonymous/a546e07484d09932eb8e to your computer and use it in GitHub Desktop.
Shared via Rust Playground
pub fn fizz_buzz(i: i32) -> String {
if i % 3 == 0 && i % 5 == 0 {
"FizzBuzz".to_string()
} else if i == 3 {
"Fizz".to_string()
} else if i == 5 {
"Buzz".to_string()
} else {
i.to_string()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn three_is_fizz() {
assert_eq!("Fizz", fizz_buzz(3));
}
#[test]
fn five_is_buzz() {
assert_eq!("Buzz", fizz_buzz(5));
}
#[test]
fn fifteen_is_fizzbuzz() {
assert_eq!("FizzBuzz", fizz_buzz(15));
}
#[test]
fn two_is_two() {
assert_eq!("2", fizz_buzz(2));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment