Last active
August 29, 2015 14:02
-
-
Save madelinecr/5b977993b4ac48053d40 to your computer and use it in GitHub Desktop.
Fizzbuzz in Rust
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 three_divides(num: int) -> bool { | |
num % 3 == 0 | |
} | |
fn five_divides(num: int) -> bool { | |
num % 5 == 0 | |
} | |
fn fifteen_divides(num: int) -> bool { | |
num % 15 == 0 | |
} | |
fn main() { | |
for num in range(1, 101) { | |
println( | |
if fifteen_divides(num) { ~"FizzBuzz" } | |
else if three_divides(num) { ~"Fizz" } | |
else if five_divides(num) { ~"Buzz" } | |
else { num.to_str() } | |
); | |
} | |
} | |
#[test] | |
fn test_three_divides_three() { | |
assert!(three_divides(3)); | |
} | |
#[test] | |
fn test_five_divides_five() { | |
assert!(five_divides(5)); | |
} | |
#[test] | |
fn test_fifteen_divides_fifteen() { | |
assert!(fifteen_divides(15)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment