Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 12aa81f

Browse files
Begin exercise
1 parent a19a9f3 commit 12aa81f

File tree

5 files changed

+185
-0
lines changed

5 files changed

+185
-0
lines changed

‎reverse-string/.gitignore‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
/target/
4+
**/*.rs.bk
5+
6+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7+
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
8+
Cargo.lock

‎reverse-string/Cargo.toml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[dependencies]
2+
3+
[features]
4+
grapheme = []
5+
6+
[package]
7+
edition = "2018"
8+
name = "reverse_string"
9+
version = "1.1.0"

‎reverse-string/README.md‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Reverse String
2+
3+
Reverse a string
4+
5+
For example:
6+
input: "cool"
7+
output: "looc"
8+
9+
## Bonus
10+
Test your function on this string: `uüu` and see what happens. Try to write a function that properly
11+
reverses this string. Hint: grapheme clusters
12+
13+
To get the bonus test to run, remove the ignore flag (`#[ignore]`) from the
14+
last test, and execute the tests with:
15+
16+
```bash
17+
$ cargo test --features grapheme
18+
```
19+
20+
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.
21+
22+
[Check the documentation](https://doc.rust-lang.org/cargo/guide/dependencies.html) for instructions on how to use external crates in your projects.
23+
24+
25+
## Rust Installation
26+
27+
Refer to the [exercism help page][help-page] for Rust installation and learning
28+
resources.
29+
30+
## Writing the Code
31+
32+
Execute the tests with:
33+
34+
```bash
35+
$ cargo test
36+
```
37+
38+
All but the first test have been ignored. After you get the first test to
39+
pass, open the tests source file which is located in the `tests` directory
40+
and remove the `#[ignore]` flag from the next test and get the tests to pass
41+
again. Each separate test is a function with `#[test]` flag above it.
42+
Continue, until you pass every test.
43+
44+
If you wish to run all tests without editing the tests source file, use:
45+
46+
```bash
47+
$ cargo test -- --ignored
48+
```
49+
50+
To run a specific test, for example `some_test`, you can use:
51+
52+
```bash
53+
$ cargo test some_test
54+
```
55+
56+
If the specific test is ignored use:
57+
58+
```bash
59+
$ cargo test some_test -- --ignored
60+
```
61+
62+
To learn more about Rust tests refer to the [online test documentation][rust-tests]
63+
64+
Make sure to read the [Modules][modules] chapter if you
65+
haven't already, it will help you with organizing your files.
66+
67+
## Further improvements
68+
69+
After you have solved the exercise, please consider using the additional utilities, described in the [installation guide](https://exercism.io/tracks/rust/installation), to further refine your final solution.
70+
71+
To format your solution, inside the solution directory use
72+
73+
```bash
74+
cargo fmt
75+
```
76+
77+
To see, if your solution contains some common ineffective use cases, inside the solution directory use
78+
79+
```bash
80+
cargo clippy --all-targets
81+
```
82+
83+
## Submitting the solution
84+
85+
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.
86+
87+
## Feedback, Issues, Pull Requests
88+
89+
The [exercism/rust](https://github.com/exercism/rust) repository on 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!
90+
91+
If you want to know more about Exercism, take a look at the [contribution guide](https://github.com/exercism/docs/blob/master/contributing-to-language-tracks/README.md).
92+
93+
[help-page]: https://exercism.io/tracks/rust/learning
94+
[modules]: https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html
95+
[cargo]: https://doc.rust-lang.org/book/ch14-00-more-about-cargo.html
96+
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
97+
98+
## Source
99+
100+
Introductory challenge to reverse an input string [https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb](https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb)
101+
102+
## Submitting Incomplete Solutions
103+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

‎reverse-string/src/lib.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn reverse(input: &str) -> String {
2+
unimplemented!("Write a function to reverse {}", input);
3+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//! Tests for reverse-string
2+
//!
3+
//! Generated by [script][script] using [canonical data][canonical-data]
4+
//!
5+
//! [script]: https://github.com/exercism/rust/blob/b829ce2/bin/init_exercise.py
6+
//! [canonical-data]: https://raw.githubusercontent.com/exercism/problem-specifications/master/exercises/reverse-string/canonical_data.json
7+
8+
use reverse_string::*;
9+
10+
/// Process a single test case for the property `reverse`
11+
fn process_reverse_case(input: &str, expected: &str) {
12+
assert_eq!(&reverse(input), expected)
13+
}
14+
15+
#[test]
16+
/// empty string
17+
fn test_an_empty_string() {
18+
process_reverse_case("", "");
19+
}
20+
21+
#[test]
22+
#[ignore]
23+
/// a word
24+
fn test_a_word() {
25+
process_reverse_case("robot", "tobor");
26+
}
27+
28+
#[test]
29+
#[ignore]
30+
/// a capitalized word
31+
fn test_a_capitalized_word() {
32+
process_reverse_case("Ramen", "nemaR");
33+
}
34+
35+
#[test]
36+
#[ignore]
37+
/// a sentence with punctuation
38+
fn test_a_sentence_with_punctuation() {
39+
process_reverse_case("I'm hungry!", "!yrgnuh m'I");
40+
}
41+
42+
#[test]
43+
#[ignore]
44+
/// a palindrome
45+
fn test_a_palindrome() {
46+
process_reverse_case("racecar", "racecar");
47+
}
48+
49+
#[test]
50+
#[ignore]
51+
/// wide characters
52+
fn test_wide_characters() {
53+
process_reverse_case("子猫", "猫子");
54+
}
55+
56+
#[test]
57+
#[ignore]
58+
#[cfg(feature = "grapheme")]
59+
/// grapheme clusters
60+
fn test_grapheme_clusters() {
61+
process_reverse_case("uüu", "uüu");
62+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /