feat(rust): add create phone number kata
This commit is contained in:
parent
0c2f6e04a5
commit
0ba20655f0
1 changed files with 20 additions and 0 deletions
20
rust/tests/4_create_phone_number.rs
Normal file
20
rust/tests/4_create_phone_number.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
fn create_phone_number(numbers: &[u8]) -> String {
|
||||
let numbers = numbers.iter().map(|i| i.to_string()).collect::<String>();
|
||||
format!("({}) {}-{}", &numbers[..3], &numbers[3..6], &numbers[6..])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_expected() {
|
||||
assert_eq!(
|
||||
create_phone_number(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]),
|
||||
"(123) 456-7890"
|
||||
);
|
||||
assert_eq!(
|
||||
create_phone_number(&[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
|
||||
"(111) 111-1111"
|
||||
);
|
||||
assert_eq!(
|
||||
create_phone_number(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 9]),
|
||||
"(123) 456-7899"
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue