-
Notifications
You must be signed in to change notification settings - Fork 45
Feat/divide #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev_test
Are you sure you want to change the base?
Feat/divide #21
Changes from all commits
d170f49
446165c
114e651
91decf0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,12 @@ def add(a, b): | |
|
|
||
| def minus(a, b): | ||
| """Subtract b from a.""" | ||
| return a - b | ||
| return a - b | ||
|
|
||
| def divide(a, b): | ||
| """Divide a by b.""" | ||
| return a / b | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| def multiply(a, b): | ||
| """Multiply two numbers""" | ||
| return a * b | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [ | ||
| {"input": {"a": 2, "b": 3}, "expected": 6}, | ||
| {"input": {"a": -1, "b": 5}, "expected": -5}, | ||
| {"input": {"a": 0, "b": 100}, "expected": 0}, | ||
| {"input": {"a": 7, "b": -3}, "expected": -21}, | ||
| {"input": {"a": -4, "b": -2}, "expected": 8}, | ||
| {"input": {"a": 1, "b": 0}, "expected": 0}, | ||
| {"input": {"a": 123, "b": 456}, "expected": 56088}, | ||
| {"input": {"a": 10, "b": 10}, "expected": 100}, | ||
| {"input": {"a": 0, "b": 0}, "expected": 0}, | ||
| {"input": {"a": 999, "b": -1}, "expected": 999} | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [ | ||
| {"input": {"a": 10, "b": 2}, "expected": 5}, | ||
| {"input": {"a": -10, "b": 2}, "expected": -5}, | ||
| {"input": {"a": 0, "b": 1}, "expected": 0}, | ||
| {"input": {"a": 10, "b": -2}, "expected": -5}, | ||
| {"input": {"a": 1, "b": 3}, "expected": 0.3333333333333333}, | ||
| {"input": {"a": 100, "b": 10}, "expected": 10}, | ||
| {"input": {"a": -100, "b": -10}, "expected": 10}, | ||
| {"input": {"a": 7, "b": 7}, "expected": 1}, | ||
| {"input": {"a": 0, "b": 10}, "expected": 0}, | ||
| {"input": {"a": 10, "b": 0}, "expected_error": "ZeroDivisionError"} | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import unittest | ||
| import json | ||
| from functions import divide | ||
|
|
||
| class TestDivideFunction(unittest.TestCase): | ||
| def setUp(self): | ||
| # JSON 파일에서 테스트 케이스 로드 | ||
| with open("tests/test_cases_divide.json", "r") as f: | ||
| self.test_cases = json.load(f) | ||
|
|
||
| def test_divide(self): | ||
| for case in self.test_cases: | ||
| a = case["input"]["a"] | ||
| b = case["input"]["b"] | ||
|
|
||
| if "expected" in case: | ||
| with self.subTest(a=a, b=b): | ||
| self.assertAlmostEqual(divide(a, b), case["expected"], places=7) | ||
| elif "expected_error" in case: | ||
| with self.subTest(a=a, b=b): | ||
| with self.assertRaises(eval(case["expected_error"])): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
| divide(a, b) | ||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import json | ||
| import unittest | ||
| from functions import multiply | ||
|
|
||
| class TestMultiplyFunction(unittest.TestCase): | ||
| def test_multiply_cases(self): | ||
| with open("tests/test_cases.json", "r") as f: | ||
| test_cases = json.load(f) | ||
|
|
||
| for case in test_cases: | ||
| a = case["input"]["a"] | ||
| b = case["input"]["b"] | ||
| expected = case["expected"] | ||
| with self.subTest(a=a, b=b, expected=expected): | ||
| self.assertEqual(multiply(a, b), expected) | ||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분 어떻게 수정해주세요.