Skip to content

Commit 98100c5

Browse files
committed
Started working on the reverse-string challenge
1 parent 1cd2761 commit 98100c5

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"track":"python","exercise":"reverse-string","id":"1e667dbdaedb4731b8e76f62cda46607","url":"https://exercism.io/my/solutions/1e667dbdaedb4731b8e76f62cda46607","handle":"sinanata","is_requester":true,"auto_approve":false}

reverse-string/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Reverse String
2+
3+
Reverse a string
4+
5+
For example:
6+
input: "cool"
7+
output: "looc"
8+
9+
10+
## Exception messages
11+
12+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
13+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
14+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
15+
a message.
16+
17+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
18+
`raise Exception`, you should write:
19+
20+
```python
21+
raise Exception("Meaningful message indicating the source of the error")
22+
```
23+
24+
## Running the tests
25+
26+
To run the tests, run `pytest reverse_string_test.py`
27+
28+
Alternatively, you can tell Python to run the pytest module:
29+
`python -m pytest reverse_string_test.py`
30+
31+
### Common `pytest` options
32+
33+
- `-v` : enable verbose output
34+
- `-x` : stop running tests on first failure
35+
- `--ff` : run failures from previous test before running other test cases
36+
37+
For other options, see `python -m pytest -h`
38+
39+
## Submitting Exercises
40+
41+
Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/reverse-string` directory.
42+
43+
You can find your Exercism workspace by running `exercism debug` and looking for the line that starts with `Workspace`.
44+
45+
For more detailed information about running tests, code style and linting,
46+
please see [Running the Tests](http://exercism.io/tracks/python/tests).
47+
48+
## Source
49+
50+
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)
51+
52+
## Submitting Incomplete Solutions
53+
54+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

reverse-string/reverse_string.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def reverse(text):
2+
pass
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import unittest
2+
3+
from reverse_string import reverse
4+
5+
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0
6+
7+
8+
class ReverseStringTest(unittest.TestCase):
9+
def test_an_empty_string(self):
10+
self.assertEqual(reverse(""), "")
11+
12+
def test_a_word(self):
13+
self.assertEqual(reverse("robot"), "tobor")
14+
15+
def test_a_capitalized_word(self):
16+
self.assertEqual(reverse("Ramen"), "nemaR")
17+
18+
def test_a_sentence_with_punctuation(self):
19+
self.assertEqual(reverse("I'm hungry!"), "!yrgnuh m'I")
20+
21+
def test_a_palindrome(self):
22+
self.assertEqual(reverse("racecar"), "racecar")
23+
24+
def test_an_even_sized_word(self):
25+
self.assertEqual(reverse("drawer"), "reward")
26+
27+
28+
if __name__ == "__main__":
29+
unittest.main()

0 commit comments

Comments
 (0)