Created
December 24, 2018 01:49
-
-
Save toshimasa-nanaki/92f253ce68a4c39bd50bc2e9dbdcdd8f to your computer and use it in GitHub Desktop.
Rust テストコード確認(基本)
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 main() { | |
let mut s = String::new(); | |
std::io::stdin().read_line(&mut s).ok(); | |
println!("{}",public_function(s.trim().parse().ok().unwrap())); | |
} | |
/// これはパブリックな関数 | |
/// 渡された文字列の後ろにビックリマークをつけて返す | |
pub fn public_function(word : String) -> String { | |
private_function(word) | |
} | |
/// これはプライベートな関数 | |
/// Hello Worldの後ろにビックリマークをつける | |
fn private_function(word : String) -> String { | |
word + "!" | |
} | |
#[test] | |
fn test_public_function() { | |
assert_eq!("Hello World!", public_function("Hello World".to_string())); | |
} | |
#[test] | |
fn test_private_function() { | |
assert_eq!("Hello World!", private_function("Hello World".to_string())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment