Skip to content

Commit

Permalink
[전희선] 12주차 미션 제출 (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
heehehe authored Jul 6, 2024
1 parent fde10ab commit c6aab19
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions 8th_members/전희선/12주차.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
```
✗ tree tests
tests
├── __init__.py
├── test_normalize.py
└── text_processing.py
```
- text_processing.py
```python
def normalize(input_str):
"""
인풋으로 받는 스트링에서 아래의 규칙으로 정규화된 스트링을 반환하는 함수입니다.
* 모든 단어들은 소문자로 변환됨
* 띄어쓰기는 한칸으로 되도록 함
* 앞뒤 필요없는 띄어쓰기는 제거함
Parameters:
input_str (string): 영어로 된 대문자, 소문자, 띄어쓰기, 문장부호, 숫자로 이루어진 string
ex - " EXTRA SPACE "
Returns:
normalized_string (string): 정규회된 string
ex - 'extra space'
Examples:
>>> import text_processing as tp
>>> example = " EXTRA SPACE "
>>> tp.normalize(example)
'extra space'
"""
out = input_str.lower()
out = out.strip()
while ' ' in out:
out = out.replace(' ', ' ')
return out
```
- test_normalize.py
```python
import unittest
from text_processing import normalize


class TestTextNormalize(unittest.TestCase):
def test_normalize(self):
test_str = "This is an example."
pred = normalize(test_str)
self.assertEqual(pred, "this is an example.")

def test_extra_space(self):
test_str = " EXTRA SPACE "
pred = normalize(test_str)
self.assertEqual(pred, "extra space")

def test_uppercase(self):
test_str = "THIS IS ALL UPPERCASE!!"
pred = normalize(test_str)
self.assertEqual(pred, "this is all uppercase!!")

def test_lowercase(self):
test_str = "this is all lowercase..."
pred = normalize(test_str)
self.assertEqual(pred, "this is all lowercase...")

def test_whitespace(self):
test_str = " "
pred = normalize(test_str)
self.assertEqual(pred, "")
```
### Result
<img width="733" alt="image" src="https://github.com/heehehe/CPython-Guide/assets/41580746/d8798a21-6399-42a2-a280-5d435e9ced16">

0 comments on commit c6aab19

Please sign in to comment.