From c6aab192a23a848cc9580820336914ac3dd3a0f7 Mon Sep 17 00:00:00 2001 From: Heeseon Cheon Date: Sat, 6 Jul 2024 23:01:48 +0900 Subject: [PATCH] =?UTF-8?q?[=EC=A0=84=ED=9D=AC=EC=84=A0]=2012=EC=A3=BC?= =?UTF-8?q?=EC=B0=A8=20=EB=AF=B8=EC=85=98=20=EC=A0=9C=EC=B6=9C=20(#114)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../12\354\243\274\354\260\250.md" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "8th_members/\354\240\204\355\235\254\354\204\240/12\354\243\274\354\260\250.md" diff --git "a/8th_members/\354\240\204\355\235\254\354\204\240/12\354\243\274\354\260\250.md" "b/8th_members/\354\240\204\355\235\254\354\204\240/12\354\243\274\354\260\250.md" new file mode 100644 index 0000000..735ca80 --- /dev/null +++ "b/8th_members/\354\240\204\355\235\254\354\204\240/12\354\243\274\354\260\250.md" @@ -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 +image