diff --git a/.forge/iss-1ac610bafd4c.md b/.forge/iss-1ac610bafd4c.md new file mode 100644 index 0000000..f4f78e9 --- /dev/null +++ b/.forge/iss-1ac610bafd4c.md @@ -0,0 +1,3 @@ +# iss-1ac610bafd4c + +Forge 이슈 작업 브랜치 `forge/iss-1ac610bafd4c`. diff --git a/README.md b/README.md index 8952c08..d259bee 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ -# ssot-live +# Utility Functions +This repository contains a collection of utility functions that can be used across various projects. + +## Modules +- `math_utils`: Contains basic mathematical operations. +- `string_utils`: Provides string manipulation functions. +- `date_utils`: Handles date-related utilities. \ No newline at end of file diff --git a/tests/test_date_utils.py b/tests/test_date_utils.py new file mode 100644 index 0000000..3f74e5f --- /dev/null +++ b/tests/test_date_utils.py @@ -0,0 +1,16 @@ +import unittest +from utils.date_utils import get_current_date, format_date +from datetime import datetime + + +class TestDateUtils(unittest.TestCase): + def test_get_current_date(self): + self.assertEqual(get_current_date(), datetime.now().strftime('%Y-%m-%d')) + + def test_format_date(self): + date = datetime(2023, 1, 1) + self.assertEqual(format_date(date, '%d-%m-%Y'), '01-01-2023') + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/tests/test_math_utils.py b/tests/test_math_utils.py new file mode 100644 index 0000000..885391e --- /dev/null +++ b/tests/test_math_utils.py @@ -0,0 +1,22 @@ +import unittest +from utils.math_utils import add, subtract, multiply, divide + + +class TestMathUtils(unittest.TestCase): + def test_add(self): + self.assertEqual(add(1, 2), 3) + + def test_subtract(self): + self.assertEqual(subtract(5, 3), 2) + + def test_multiply(self): + self.assertEqual(multiply(3, 4), 12) + + def test_divide(self): + self.assertEqual(divide(10, 2), 5) + with self.assertRaises(ValueError): + divide(10, 0) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/tests/test_string_utils.py b/tests/test_string_utils.py new file mode 100644 index 0000000..21c6248 --- /dev/null +++ b/tests/test_string_utils.py @@ -0,0 +1,15 @@ +import unittest +from utils.string_utils import capitalize_first_letter, reverse_string + + +class TestStringUtils(unittest.TestCase): + def test_capitalize_first_letter(self): + self.assertEqual(capitalize_first_letter('hello'), 'Hello') + self.assertEqual(capitalize_first_letter(''), '') + + def test_reverse_string(self): + self.assertEqual(reverse_string('hello'), 'olleh') + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 0000000..fe90d99 --- /dev/null +++ b/utils/__init__.py @@ -0,0 +1,3 @@ +# Utility Functions Package + +# This package contains various utility functions for different purposes. \ No newline at end of file diff --git a/utils/date_utils.py b/utils/date_utils.py new file mode 100644 index 0000000..df1b210 --- /dev/null +++ b/utils/date_utils.py @@ -0,0 +1,11 @@ +from datetime import datetime + + +def get_current_date(): + """Returns the current date as a string in YYYY-MM-DD format.""" + return datetime.now().strftime('%Y-%m-%d') + + +def format_date(date, format='%Y-%m-%d'): + """Formats a given date to the specified format.""" + return date.strftime(format) \ No newline at end of file diff --git a/utils/math_utils.py b/utils/math_utils.py new file mode 100644 index 0000000..d8fe83c --- /dev/null +++ b/utils/math_utils.py @@ -0,0 +1,20 @@ +def add(a, b): + """Returns the sum of two numbers.""" + return a + b + + +def subtract(a, b): + """Returns the difference of two numbers.""" + return a - b + + +def multiply(a, b): + """Returns the product of two numbers.""" + return a * b + + +def divide(a, b): + """Returns the quotient of two numbers. Raises ValueError on division by zero.""" + if b == 0: + raise ValueError('Cannot divide by zero') + return a / b \ No newline at end of file diff --git a/utils/string_utils.py b/utils/string_utils.py new file mode 100644 index 0000000..253d707 --- /dev/null +++ b/utils/string_utils.py @@ -0,0 +1,10 @@ +def capitalize_first_letter(s): + """Capitalizes the first letter of a string.""" + if not s: + return s + return s[0].upper() + s[1:] + + +def reverse_string(s): + """Reverses the given string.""" + return s[::-1] \ No newline at end of file