Complete reverse string
This commit is contained in:
parent
d2ff52dc39
commit
1ef9941f2d
3 changed files with 7 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
|||
[dependencies]
|
||||
unicode-segmentation = "1.10.1"
|
||||
|
||||
[features]
|
||||
grapheme = []
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
use unicode_segmentation::UnicodeSegmentation;
|
||||
pub fn reverse(input: &str) -> String {
|
||||
unimplemented!("Write a function to reverse {}", input);
|
||||
let mut output:String = String::new();
|
||||
for i in input.graphemes(true).rev(){
|
||||
output.push_str(i);
|
||||
}
|
||||
output
|
||||
}
|
||||
|
|
|
@ -19,49 +19,42 @@ fn test_an_empty_string() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
/// a word
|
||||
fn test_a_word() {
|
||||
process_reverse_case("robot", "tobor");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
/// a capitalized word
|
||||
fn test_a_capitalized_word() {
|
||||
process_reverse_case("Ramen", "nemaR");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
/// a sentence with punctuation
|
||||
fn test_a_sentence_with_punctuation() {
|
||||
process_reverse_case("I'm hungry!", "!yrgnuh m'I");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
/// a palindrome
|
||||
fn test_a_palindrome() {
|
||||
process_reverse_case("racecar", "racecar");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
/// an even-sized word
|
||||
fn test_an_even_sized_word() {
|
||||
process_reverse_case("drawer", "reward");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
/// wide characters
|
||||
fn test_wide_characters() {
|
||||
process_reverse_case("子猫", "猫子");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
#[cfg(feature = "grapheme")]
|
||||
/// grapheme clusters
|
||||
fn test_grapheme_clusters() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue