Created
October 30, 2015 18:39
-
-
Save anonymous/a546e07484d09932eb8e to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains hidden or 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
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