mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-12-21 06:13:10 -05:00
Rust: completed Reverse String again
This commit is contained in:
parent
59a1cb14fa
commit
852758eb9c
5 changed files with 25 additions and 15 deletions
|
@ -1 +1 @@
|
|||
{"track":"rust","exercise":"reverse-string","id":"aeec5dd024f94c60b89e66907f4e90b9","url":"https://exercism.org/tracks/rust/exercises/reverse-string","handle":"Chomp1295","is_requester":true,"auto_approve":false}
|
||||
{"track":"rust","exercise":"reverse-string","id":"f97879b6def647a5bf82751034c483e3","url":"https://exercism.org/tracks/rust/exercises/reverse-string","handle":"Chomp1295","is_requester":true,"auto_approve":false}
|
|
@ -1,9 +1,10 @@
|
|||
[dependencies]
|
||||
|
||||
[features]
|
||||
grapheme = []
|
||||
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "reverse_string"
|
||||
version = "1.2.0"
|
||||
|
||||
[features]
|
||||
grapheme = []
|
||||
|
||||
[dependencies]
|
||||
unicode-segmentation = "=1.11.0"
|
||||
|
|
|
@ -21,17 +21,20 @@ Some examples:
|
|||
|
||||
## Bonus
|
||||
|
||||
Test your function on this string: `uüu` and see what happens. Try to write a function that properly
|
||||
reverses this string. Hint: grapheme clusters
|
||||
Test your function on this string: `uüu` and see what happens.
|
||||
Try to write a function that properly reverses this string.
|
||||
Hint: grapheme clusters
|
||||
|
||||
To get the bonus test to run, remove the ignore flag (`#[ignore]`) from the
|
||||
last test, and execute the tests with:
|
||||
To get the bonus test to run, remove the ignore flag (`#[ignore]`) from the last test, and execute the tests with:
|
||||
|
||||
```bash
|
||||
$ cargo test --features grapheme
|
||||
cargo test --features grapheme
|
||||
```
|
||||
|
||||
You will need to use external libraries (a `crate` in rust lingo) for the bonus task. A good place to look for those is [crates.io](https://crates.io/), the official repository of crates.
|
||||
You will need to use external libraries (a `crate` in rust lingo) for the bonus task.
|
||||
A good place to look for those is [crates.io](https://crates.io/), the official repository of crates.
|
||||
Please remember that only a limited set of crates is supported by our test runner.
|
||||
The full list is in [this file](https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml) under the section `[dependencies]`.
|
||||
|
||||
[Check the documentation](https://doc.rust-lang.org/cargo/guide/dependencies.html) for instructions on how to use external crates in your projects.
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
pub fn reverse(input: &str) -> String {
|
||||
input.chars().rev().collect()
|
||||
input.graphemes(true).rev().collect()
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ fn an_empty_string() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
|
||||
fn a_word() {
|
||||
let input = "robot";
|
||||
let output = reverse(input);
|
||||
|
@ -17,6 +18,7 @@ fn a_word() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
|
||||
fn a_capitalized_word() {
|
||||
let input = "Ramen";
|
||||
let output = reverse(input);
|
||||
|
@ -25,6 +27,7 @@ fn a_capitalized_word() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
|
||||
fn a_sentence_with_punctuation() {
|
||||
let input = "I'm hungry!";
|
||||
let output = reverse(input);
|
||||
|
@ -33,6 +36,7 @@ fn a_sentence_with_punctuation() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
|
||||
fn a_palindrome() {
|
||||
let input = "racecar";
|
||||
let output = reverse(input);
|
||||
|
@ -41,6 +45,7 @@ fn a_palindrome() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
|
||||
fn an_even_sized_word() {
|
||||
let input = "drawer";
|
||||
let output = reverse(input);
|
||||
|
@ -49,6 +54,7 @@ fn an_even_sized_word() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
|
||||
fn wide_characters() {
|
||||
let input = "子猫";
|
||||
let output = reverse(input);
|
||||
|
@ -57,7 +63,6 @@ fn wide_characters() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
#[cfg(feature = "grapheme")]
|
||||
fn grapheme_cluster_with_pre_combined_form() {
|
||||
let input = "Würstchenstand";
|
||||
|
@ -67,7 +72,6 @@ fn grapheme_cluster_with_pre_combined_form() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
#[cfg(feature = "grapheme")]
|
||||
fn grapheme_clusters() {
|
||||
let input = "ผู้เขียนโปรแกรม";
|
||||
|
|
Loading…
Reference in a new issue