two-fer

1. Readme

Two Fer

Two-fer2-fer是 two for one 的缩写。One for you and one for me。

"One for X, one for me."

当 X 是一个名字或you

如果给定名称是Alice,结果应该是One for Alice, one for me.。如果没有给出名称,结果应该是One for you, one for me.

资源

https://en.wikipedia.org/wiki/Two-fer

2. 开始你的表演

pub fn twofer(name: &str) -> String {
   unimplemented!("One for {}, one for me.", name);
}

3. 测试代码查看


# #![allow(unused_variables)]
#fn main() {
#[test]
fn empty_string() {
   assert_eq!(twofer(""), "One for you, one for me.");
}

#[test]
//#[ignore]
fn alice() {
   assert_eq!(twofer("Alice"), "One for Alice, one for me.");
}

#[test]
//#[ignore]
fn bob() {
   assert_eq!(twofer("Bob"), "One for Bob, one for me.");
}

#}

4. 答案


# #![allow(unused_variables)]
#fn main() {
pub fn twofer(name: &str) -> String {
   match name {
       "" => "One for you, one for me.".to_string(),
       _ => format!("One for {}, one for me.", name),
   }
}

#}



填充/相关