Skip to content

Commit c2a58aa

Browse files
committed
Started working on the acronym challenge
1 parent 1b126b0 commit c2a58aa

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

acronym/.exercism/metadata.json

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

acronym/README.md

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

acronym/acronym.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def abbreviate(words):
2+
pass

acronym/acronym_test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import unittest
2+
3+
from acronym import abbreviate
4+
5+
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.7.0
6+
7+
8+
class AcronymTest(unittest.TestCase):
9+
def test_basic(self):
10+
self.assertEqual(abbreviate("Portable Network Graphics"), "PNG")
11+
12+
def test_lowercase_words(self):
13+
self.assertEqual(abbreviate("Ruby on Rails"), "ROR")
14+
15+
def test_punctuation(self):
16+
self.assertEqual(abbreviate("First In, First Out"), "FIFO")
17+
18+
def test_all_caps_word(self):
19+
self.assertEqual(abbreviate("GNU Image Manipulation Program"), "GIMP")
20+
21+
def test_punctuation_without_whitespace(self):
22+
self.assertEqual(abbreviate("Complementary metal-oxide semiconductor"), "CMOS")
23+
24+
def test_very_long_abbreviation(self):
25+
self.assertEqual(
26+
abbreviate(
27+
"Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me"
28+
),
29+
"ROTFLSHTMDCOALM",
30+
)
31+
32+
def test_consecutive_delimiters(self):
33+
self.assertEqual(abbreviate("Something - I made up from thin air"), "SIMUFTA")
34+
35+
def test_apostrophes(self):
36+
self.assertEqual(abbreviate("Halley's Comet"), "HC")
37+
38+
def test_underscore_emphasis(self):
39+
self.assertEqual(abbreviate("The Road _Not_ Taken"), "TRNT")
40+
41+
42+
if __name__ == "__main__":
43+
unittest.main()

0 commit comments

Comments
 (0)