Skip to content

Commit 6e2c228

Browse files
committed
initial
1 parent feb3064 commit 6e2c228

File tree

5 files changed

+175
-0
lines changed

5 files changed

+175
-0
lines changed

.qlty/qlty.toml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# This file was automatically generated by `qlty init`.
2+
# You can modify it to suit your needs.
3+
# We recommend you to commit this file to your repository.
4+
#
5+
# This configuration is used by both Qlty CLI and Qlty Cloud.
6+
#
7+
# Qlty CLI -- Code quality toolkit for developers
8+
# Qlty Cloud -- Fully automated Code Health Platform
9+
#
10+
# Try Qlty Cloud: https://qlty.sh
11+
#
12+
# For a guide to configuration, visit https://qlty.sh/d/config
13+
# Or for a full reference, visit https://qlty.sh/d/qlty-toml
14+
config_version = "0"
15+
16+
exclude_patterns = [
17+
"*_min.*",
18+
"*-min.*",
19+
"*.min.*",
20+
"**/*.d.ts",
21+
"**/.yarn/**",
22+
"**/bower_components/**",
23+
"**/build/**",
24+
"**/cache/**",
25+
"**/config/**",
26+
"**/db/**",
27+
"**/deps/**",
28+
"**/dist/**",
29+
"**/extern/**",
30+
"**/external/**",
31+
"**/generated/**",
32+
"**/Godeps/**",
33+
"**/gradlew/**",
34+
"**/mvnw/**",
35+
"**/node_modules/**",
36+
"**/protos/**",
37+
"**/seed/**",
38+
"**/target/**",
39+
"**/testdata/**",
40+
"**/vendor/**",
41+
"**/assets/**",
42+
]
43+
44+
test_patterns = [
45+
"**/test/**",
46+
"**/spec/**",
47+
"**/*.test.*",
48+
"**/*.spec.*",
49+
"**/*_test.*",
50+
"**/*_spec.*",
51+
"**/test_*.*",
52+
"**/spec_*.*",
53+
]
54+
55+
[smells]
56+
mode = "comment"
57+
58+
[[source]]
59+
name = "default"
60+
default = true
61+
62+
[[plugin]]
63+
name = "markdownlint"
64+
mode = "comment"
65+
66+
[[plugin]]
67+
name = "prettier"
68+
69+
[[plugin]]
70+
name = "trufflehog"

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[tool.coverage.run]
2+
omit = [
3+
"tests/*",
4+
]

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage

sample/calculator.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
def add(a, b):
2+
"""
3+
Adds two numbers together.
4+
5+
Args:
6+
a (int): The first number.
7+
b (int): The second number.
8+
9+
Returns:
10+
int: The sum of the two numbers.
11+
"""
12+
return a + b
13+
14+
def subtract(a, b):
15+
"""
16+
Subtracts the second number from the first.
17+
18+
Args:
19+
a (int): The first number.
20+
b (int): The second number.
21+
22+
Returns:
23+
int: The difference of the two numbers.
24+
"""
25+
return a - b
26+
27+
def multiply(a, b):
28+
"""
29+
Multiplies two numbers together.
30+
Args:
31+
a (int): The first number.
32+
b (int): The second number.
33+
Returns:
34+
int: The product of the two numbers.
35+
"""
36+
return a * b
37+
38+
def divide(a, b):
39+
"""
40+
Divides the first number by the second.
41+
Args:
42+
a (int): The first number.
43+
b (int): The second number.
44+
Returns:
45+
float: The quotient of the two numbers.
46+
Raises:
47+
ZeroDivisionError: If the second number is zero.
48+
"""
49+
if b == 0:
50+
raise ZeroDivisionError("division by zero")
51+
return a / b
52+
53+
def main():
54+
"""
55+
Main function to demonstrate the calculator operations.
56+
"""
57+
print("Simple Calculator")
58+
print("1. Add")
59+
print("2. Subtract")
60+
print("3. Multiply")
61+
print("4. Divide")
62+
choice = input("Enter your choice (1-4): ")
63+
64+
a = float(input("Enter first number: "))
65+
b = float(input("Enter second number: "))
66+
67+
if choice == '1':
68+
print(f"{a} + {b} = {add(a, b)}")
69+
elif choice == '2':
70+
print(f"{a} - {b} = {subtract(a, b)}")
71+
elif choice == '3':
72+
print(f"{a} * {b} = {multiply(a, b)}")
73+
elif choice == '4':
74+
try:
75+
print(f"{a} / {b} = {divide(a, b)}")
76+
except ZeroDivisionError as e:
77+
print(e)
78+
else:
79+
print("Invalid choice.")
80+
81+
if __name__ == "__main__":
82+
main()

tests/test_calculator.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import unittest
2+
from sample.calculator import add, divide
3+
4+
class TestSample(unittest.TestCase):
5+
6+
def test_add(self):
7+
self.assertEqual(add(1, 2), 3)
8+
self.assertEqual(add(-1, 1), 0)
9+
self.assertEqual(add(0, 0), 0)
10+
11+
def test_divide(self):
12+
self.assertEqual(divide(6, 3), 2)
13+
self.assertEqual(divide(5, 2), 2.5)
14+
with self.assertRaises(ZeroDivisionError):
15+
divide(1, 0)
16+
17+
if __name__ == '__main__':
18+
unittest.main()

0 commit comments

Comments
 (0)