summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rust/reverse-string/.exercism/config.json38
-rw-r--r--rust/reverse-string/.exercism/metadata.json1
-rw-r--r--rust/reverse-string/.gitignore8
-rw-r--r--rust/reverse-string/Cargo.toml9
-rw-r--r--rust/reverse-string/HELP.md86
-rw-r--r--rust/reverse-string/README.md65
-rw-r--r--rust/reverse-string/src/lib.rs3
-rw-r--r--rust/reverse-string/tests/reverse-string.rs77
8 files changed, 287 insertions, 0 deletions
diff --git a/rust/reverse-string/.exercism/config.json b/rust/reverse-string/.exercism/config.json
new file mode 100644
index 0000000..6fa8c43
--- /dev/null
+++ b/rust/reverse-string/.exercism/config.json
@@ -0,0 +1,38 @@
+{
+ "authors": [
+ "coriolinus"
+ ],
+ "contributors": [
+ "cbzehner",
+ "ccouzens",
+ "cwhakes",
+ "efx",
+ "ErikSchierboom",
+ "hunger",
+ "lutostag",
+ "ocstl",
+ "PaulT89",
+ "petertseng",
+ "rofrol",
+ "rrredface",
+ "stringparser",
+ "TheDarkula",
+ "xakon",
+ "ZapAnton"
+ ],
+ "files": {
+ "solution": [
+ "src/lib.rs",
+ "Cargo.toml"
+ ],
+ "test": [
+ "tests/reverse-string.rs"
+ ],
+ "example": [
+ ".meta/example.rs"
+ ]
+ },
+ "blurb": "Reverse a given string.",
+ "source": "Introductory challenge to reverse an input string",
+ "source_url": "https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb"
+}
diff --git a/rust/reverse-string/.exercism/metadata.json b/rust/reverse-string/.exercism/metadata.json
new file mode 100644
index 0000000..e27a026
--- /dev/null
+++ b/rust/reverse-string/.exercism/metadata.json
@@ -0,0 +1 @@
+{"track":"rust","exercise":"reverse-string","id":"5d3bb07e5895478c986cf6b2d4c58918","url":"https://exercism.org/tracks/rust/exercises/reverse-string","handle":"dim13","is_requester":true,"auto_approve":false} \ No newline at end of file
diff --git a/rust/reverse-string/.gitignore b/rust/reverse-string/.gitignore
new file mode 100644
index 0000000..db7f315
--- /dev/null
+++ b/rust/reverse-string/.gitignore
@@ -0,0 +1,8 @@
+# Generated by Cargo
+# will have compiled files and executables
+/target/
+**/*.rs.bk
+
+# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
+# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
+Cargo.lock
diff --git a/rust/reverse-string/Cargo.toml b/rust/reverse-string/Cargo.toml
new file mode 100644
index 0000000..52b902c
--- /dev/null
+++ b/rust/reverse-string/Cargo.toml
@@ -0,0 +1,9 @@
+[dependencies]
+
+[features]
+grapheme = []
+
+[package]
+edition = "2021"
+name = "reverse_string"
+version = "1.2.0"
diff --git a/rust/reverse-string/HELP.md b/rust/reverse-string/HELP.md
new file mode 100644
index 0000000..67add76
--- /dev/null
+++ b/rust/reverse-string/HELP.md
@@ -0,0 +1,86 @@
+# Help
+
+## Running the tests
+
+Execute the tests with:
+
+```bash
+$ cargo test
+```
+
+All but the first test have been ignored. After you get the first test to
+pass, open the tests source file which is located in the `tests` directory
+and remove the `#[ignore]` flag from the next test and get the tests to pass
+again. Each separate test is a function with `#[test]` flag above it.
+Continue, until you pass every test.
+
+If you wish to run _only ignored_ tests without editing the tests source file, use:
+
+```bash
+$ cargo test -- --ignored
+```
+
+If you are using Rust 1.51 or later, you can run _all_ tests with
+
+```bash
+$ cargo test -- --include-ignored
+```
+
+To run a specific test, for example `some_test`, you can use:
+
+```bash
+$ cargo test some_test
+```
+
+If the specific test is ignored, use:
+
+```bash
+$ cargo test some_test -- --ignored
+```
+
+To learn more about Rust tests refer to the online [test documentation][rust-tests].
+
+[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
+- The [Rust track's programming category on the forum](https://forum.exercism.org/c/programming/rust)
+- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+## Rust Installation
+
+Refer to the [exercism help page][help-page] for Rust installation and learning
+resources.
+
+## Submitting the solution
+
+Generally you should submit all files in which you implemented your solution (`src/lib.rs` in most cases). If you are using any external crates, please consider submitting the `Cargo.toml` file. This will make the review process faster and clearer.
+
+## Feedback, Issues, Pull Requests
+
+The GitHub [track repository][github] is the home for all of the Rust exercises. If you have feedback about an exercise, or want to help implement new exercises, head over there and create an issue. Members of the rust track team are happy to help!
+
+If you want to know more about Exercism, take a look at the [contribution guide].
+
+## Submitting Incomplete Solutions
+It's possible to submit an incomplete solution so you can see how others have completed the exercise.
+
+[help-page]: https://exercism.org/tracks/rust/learning
+[github]: https://github.com/exercism/rust
+[contribution guide]: https://exercism.org/docs/community/contributors \ No newline at end of file
diff --git a/rust/reverse-string/README.md b/rust/reverse-string/README.md
new file mode 100644
index 0000000..afd18f8
--- /dev/null
+++ b/rust/reverse-string/README.md
@@ -0,0 +1,65 @@
+# Reverse String
+
+Welcome to Reverse String on Exercism's Rust Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Introduction
+
+Reversing strings (reading them from right to left, rather than from left to right) is a surprisingly common task in programming.
+
+For example, in bioinformatics, reversing the sequence of DNA or RNA strings is often important for various analyses, such as finding complementary strands or identifying palindromic sequences that have biological significance.
+
+## Instructions
+
+Your task is to reverse a given string.
+
+Some examples:
+
+- Turn `"stressed"` into `"desserts"`.
+- Turn `"strops"` into `"sports"`.
+- Turn `"racecar"` into `"racecar"`.
+
+## 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
+
+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
+```
+
+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.
+
+[Check the documentation](https://doc.rust-lang.org/cargo/guide/dependencies.html) for instructions on how to use external crates in your projects.
+
+## Source
+
+### Created by
+
+- @coriolinus
+
+### Contributed to by
+
+- @cbzehner
+- @ccouzens
+- @cwhakes
+- @efx
+- @ErikSchierboom
+- @hunger
+- @lutostag
+- @ocstl
+- @PaulT89
+- @petertseng
+- @rofrol
+- @rrredface
+- @stringparser
+- @TheDarkula
+- @xakon
+- @ZapAnton
+
+### Based on
+
+Introductory challenge to reverse an input string - https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb \ No newline at end of file
diff --git a/rust/reverse-string/src/lib.rs b/rust/reverse-string/src/lib.rs
new file mode 100644
index 0000000..0393f10
--- /dev/null
+++ b/rust/reverse-string/src/lib.rs
@@ -0,0 +1,3 @@
+pub fn reverse(input: &str) -> String {
+ input.chars().rev().collect()
+}
diff --git a/rust/reverse-string/tests/reverse-string.rs b/rust/reverse-string/tests/reverse-string.rs
new file mode 100644
index 0000000..cc16866
--- /dev/null
+++ b/rust/reverse-string/tests/reverse-string.rs
@@ -0,0 +1,77 @@
+use reverse_string::*;
+
+#[test]
+fn an_empty_string() {
+ let input = "";
+ let output = reverse(input);
+ let expected = "";
+ assert_eq!(output, expected);
+}
+
+#[test]
+fn a_word() {
+ let input = "robot";
+ let output = reverse(input);
+ let expected = "tobor";
+ assert_eq!(output, expected);
+}
+
+#[test]
+fn a_capitalized_word() {
+ let input = "Ramen";
+ let output = reverse(input);
+ let expected = "nemaR";
+ assert_eq!(output, expected);
+}
+
+#[test]
+fn a_sentence_with_punctuation() {
+ let input = "I'm hungry!";
+ let output = reverse(input);
+ let expected = "!yrgnuh m'I";
+ assert_eq!(output, expected);
+}
+
+#[test]
+fn a_palindrome() {
+ let input = "racecar";
+ let output = reverse(input);
+ let expected = "racecar";
+ assert_eq!(output, expected);
+}
+
+#[test]
+fn an_even_sized_word() {
+ let input = "drawer";
+ let output = reverse(input);
+ let expected = "reward";
+ assert_eq!(output, expected);
+}
+
+#[test]
+fn wide_characters() {
+ let input = "子猫";
+ let output = reverse(input);
+ let expected = "猫子";
+ assert_eq!(output, expected);
+}
+
+#[test]
+#[ignore]
+#[cfg(feature = "grapheme")]
+fn grapheme_cluster_with_pre_combined_form() {
+ let input = "Würstchenstand";
+ let output = reverse(input);
+ let expected = "dnatsnehctsrüW";
+ assert_eq!(output, expected);
+}
+
+#[test]
+#[ignore]
+#[cfg(feature = "grapheme")]
+fn grapheme_clusters() {
+ let input = "ผู้เขียนโปรแกรม";
+ let output = reverse(input);
+ let expected = "มรกแรปโนยขีเผู้";
+ assert_eq!(output, expected);
+}