Solve rust/reverse-string
This commit is contained in:
parent
3823af76a5
commit
2a735f6868
4 changed files with 9 additions and 8 deletions
|
@ -35,6 +35,7 @@
|
|||
{package = pkgs.exercism;}
|
||||
{package = pkgs.nil;}
|
||||
{package = pkgs.rustc;}
|
||||
{package = pkgs.rustfmt;}
|
||||
{package = pkgs.rust-analyzer;}
|
||||
];
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
[dependencies]
|
||||
unicode-segmentation = "1.10.1"
|
||||
|
||||
[features]
|
||||
grapheme = []
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
pub fn reverse(input: &str) -> String {
|
||||
todo!("Write a function to reverse {input}");
|
||||
if cfg!(feature = "grapheme") {
|
||||
input.graphemes(true).rev().collect()
|
||||
} else {
|
||||
input.chars().rev().collect()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,49 +19,42 @@ fn an_empty_string() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
/// a word
|
||||
fn a_word() {
|
||||
process_reverse_case("robot", "tobor");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
/// a capitalized word
|
||||
fn a_capitalized_word() {
|
||||
process_reverse_case("Ramen", "nemaR");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
/// a sentence with punctuation
|
||||
fn a_sentence_with_punctuation() {
|
||||
process_reverse_case("I'm hungry!", "!yrgnuh m'I");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
/// a palindrome
|
||||
fn a_palindrome() {
|
||||
process_reverse_case("racecar", "racecar");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
/// an even-sized word
|
||||
fn an_even_sized_word() {
|
||||
process_reverse_case("drawer", "reward");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
/// wide characters
|
||||
fn wide_characters() {
|
||||
process_reverse_case("子猫", "猫子");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
#[cfg(feature = "grapheme")]
|
||||
/// grapheme clusters
|
||||
fn grapheme_clusters() {
|
||||
|
|
Loading…
Reference in a new issue