Last active
August 29, 2015 14:03
-
-
Save cookrn/7e19aff88845e86f62a8 to your computer and use it in GitHub Desktop.
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
example21.rs:70:13: 70:19 error: mismatched types: expected `&str` but found `collections::string::String` (expected &-ptr but found struct collections::string::String) | |
example21.rs:70 println(answer); | |
^~~~~~ | |
error: aborting due to previous error |
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
use std::io::println; | |
fn is_three(num: int) -> bool { | |
num % 3 == 0 | |
} | |
fn is_five(num: int) -> bool { | |
num % 5 == 0 | |
} | |
fn is_fifteen(num: int) -> bool { | |
num % 15 == 0 | |
} | |
#[test] | |
fn test_is_three_with_not_three() { | |
if is_three(1) { | |
fail!("One is not three"); | |
} | |
} | |
#[test] | |
fn test_is_three_with_three() { | |
if !is_three(3) { | |
fail!("Three should be three"); | |
} | |
} | |
#[test] | |
fn test_is_five_with_not_five() { | |
if is_five(1) { | |
fail!("One is not five"); | |
} | |
} | |
#[test] | |
fn test_is_five_with_five() { | |
if !is_five(5) { | |
fail!("Five should be five"); | |
} | |
} | |
#[test] | |
fn test_is_fifteen_with_not_fifteen() { | |
if is_fifteen(1) { | |
fail!("One is not fifteen"); | |
} | |
} | |
#[test] | |
fn test_is_fifteen_with_fifteen() { | |
if !is_fifteen(15) { | |
fail!("Fifteen should be fifteen"); | |
} | |
} | |
fn main() { | |
for num in range(1i, 101) { | |
let answer = | |
if is_fifteen(num) { | |
"FizzBuzz".to_string() | |
} else if is_three(num) { | |
"Fizz".to_string() | |
} else if is_five(num) { | |
"Buzz".to_string() | |
} else { | |
num.to_str() | |
}; | |
println(answer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment