Solve rust/reverse-string

This commit is contained in:
Avery Winters 2023-10-11 10:56:50 -05:00
parent 3823af76a5
commit 2a735f6868
Signed by: avery
SSH key fingerprint: SHA256:eesvLB5MMqHLZrAMFt6kEhqJWnASMLcET6Sgmw0FqZI
4 changed files with 9 additions and 8 deletions

View file

@ -35,6 +35,7 @@
{package = pkgs.exercism;}
{package = pkgs.nil;}
{package = pkgs.rustc;}
{package = pkgs.rustfmt;}
{package = pkgs.rust-analyzer;}
];
};

View file

@ -1,4 +1,5 @@
[dependencies]
unicode-segmentation = "1.10.1"
[features]
grapheme = []

View file

@ -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()
}
}

View file

@ -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() {