Skip to content

Commit 8a0ac5b

Browse files
authored
Merge pull request #391 from coriolinus/add-reverse-string-exercise
Add exercise reverse-string
2 parents 65b9c8d + 454160c commit 8a0ac5b

File tree

7 files changed

+134
-0
lines changed

7 files changed

+134
-0
lines changed

config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@
4747
"Mutable string"
4848
]
4949
},
50+
{
51+
"uuid": "ecf8d1e3-9400-4d1a-8326-2e2820bce024",
52+
"slug": "reverse-string",
53+
"core": false,
54+
"unlocked_by": null,
55+
"difficulty": 1,
56+
"topics": [
57+
"String",
58+
"&str",
59+
"Iterator"
60+
]
61+
},
5062
{
5163
"uuid": "ee5048a7-c625-434d-a0a2-4fd54757ee02",
5264
"slug": "nth-prime",

exercises/reverse-string/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ignore Cargo.lock if creating a library
2+
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
3+
Cargo.lock

exercises/reverse-string/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "reverse_string"
3+
version = "1.0.0"
4+
authors = ["Peter Goodspeed-Niklaus <[email protected]>"]
5+
6+
[dependencies]

exercises/reverse-string/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# reverse-string
2+
3+
Reverse a string
4+
5+
For example:
6+
input: "cool"
7+
output: "looc"
8+
9+
## Rust Installation
10+
11+
Refer to the [exercism help page][help-page] for Rust installation and learning
12+
resources.
13+
14+
## Writing the Code
15+
16+
Execute the tests with:
17+
18+
```bash
19+
$ cargo test
20+
```
21+
22+
All but the first test have been ignored. After you get the first test to
23+
pass, remove the ignore flag (`#[ignore]`) from the next test and get the tests
24+
to pass again. The test file is located in the `tests` directory. You can
25+
also remove the ignore flag from all the tests to get them to run all at once
26+
if you wish.
27+
28+
Make sure to read the [Modules](https://doc.rust-lang.org/book/second-edition/ch07-00-modules.html) chapter if you
29+
haven't already, it will help you with organizing your files.
30+
31+
## Feedback, Issues, Pull Requests
32+
33+
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](https://github.com/orgs/exercism/teams/rust) are happy to help!
34+
35+
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).
36+
37+
[help-page]: http://exercism.io/languages/rust
38+
[modules]: https://doc.rust-lang.org/book/second-edition/ch07-00-modules.html
39+
[cargo]: https://doc.rust-lang.org/book/second-edition/ch14-00-more-about-cargo.html
40+
41+
## Source
42+
43+
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)
44+
45+
## Submitting Incomplete Solutions
46+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

exercises/reverse-string/example.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! Example implementation for reverse-string
2+
3+
pub fn reverse(input: &str) -> String {
4+
let mut output = String::with_capacity(input.len());
5+
output.extend(input.chars().rev());
6+
output
7+
}

exercises/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(_: &str) -> String {
2+
unimplemented!()
3+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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/master/bin/init_exercise.py
6+
//! [canonical-data]: https://raw.githubusercontent.com/exercism/problem-specifications/master/exercises/reverse-string/canonical_data.json
7+
8+
9+
extern crate reverse_string;
10+
use reverse_string::*;
11+
12+
/// Process a single test case for the property `reverse`
13+
fn process_reverse_case(input: &str, expected: &str) {
14+
assert_eq!(
15+
&reverse(input),
16+
expected
17+
)
18+
}
19+
20+
21+
#[test]
22+
/// empty string
23+
fn test_empty_string() {
24+
process_reverse_case("", "");
25+
}
26+
27+
28+
#[test]
29+
#[ignore]
30+
/// a word
31+
fn test_a_word() {
32+
process_reverse_case("robot", "tobor");
33+
}
34+
35+
36+
#[test]
37+
#[ignore]
38+
/// a capitalized word
39+
fn test_a_capitalized_word() {
40+
process_reverse_case("Ramen", "nemaR");
41+
}
42+
43+
44+
#[test]
45+
#[ignore]
46+
/// a sentence with punctuation
47+
fn test_a_sentence_with_punctuation() {
48+
process_reverse_case("I'm hungry!", "!yrgnuh m'I");
49+
}
50+
51+
52+
#[test]
53+
#[ignore]
54+
/// a palindrome
55+
fn test_a_palindrome() {
56+
process_reverse_case("racecar", "racecar");
57+
}

0 commit comments

Comments
 (0)