Skip to content

Commit 66cc751

Browse files
committed
acronym: implement exercise
acronym: initial implementation acronym: style fixes - remove the line break in line 24/25 (acronym_test.py) - remove the unnecessary brackets in line 6 (re.findall..) (example.py) - remove the line break in line 5/6 (example.py) acronym: add acronym to config.json after sum-of-multiples
1 parent cf038f6 commit 66cc751

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"sieve",
2323
"atbash-cipher",
2424
"sum-of-multiples",
25+
"acronym",
2526
"say",
2627
"largest-series-product",
2728
"kindergarten-garden",

exercises/acronym/acronym_test.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import unittest
2+
3+
from acronym import abbreviate
4+
5+
6+
class AcronymTest(unittest.TestCase):
7+
8+
def test_basic(self):
9+
self.assertEqual('PNG', abbreviate('Portable Network Graphics'))
10+
11+
def test_lowercase_words(self):
12+
self.assertEqual('ROR', abbreviate('Ruby on Rails'))
13+
14+
def test_camelcase(self):
15+
self.assertEqual('HTML', abbreviate('HyperText Markup Language'))
16+
17+
def test_punctuation(self):
18+
self.assertEqual('FIFO', abbreviate('First In, First Out'))
19+
20+
def test_all_caps_words(self):
21+
self.assertEqual('PHP', abbreviate('PHP: Hypertext Preprocessor'))
22+
23+
def test_hyphenated(self):
24+
self.assertEqual('CMOS', abbreviate('Complementary metal-oxide semiconductor'))
25+
26+
27+
if __name__ == '__main__':
28+
unittest.main()

exercises/acronym/example.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import re
2+
3+
4+
def abbreviate(words):
5+
regex = '[A-Z]+[a-z]*|[a-z]+'
6+
return ''.join(word[0].upper() for word in re.findall(regex, words))

0 commit comments

Comments
 (0)