-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArithmetic.py
46 lines (28 loc) · 999 Bytes
/
Arithmetic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
import unittest
def arithmetic(first, second, operator):
if str(operator) == '+':
summary = first + second
elif str(operator) == '-':
summary = first - second
elif str(operator) == '/':
summary = first / second
elif str(operator) == '*':
summary = first * second
else:
summary = "Неизвестная операция"
return summary
print(arithmetic(3, 4, '*'))
class ArithmeticTestCase(unittest.TestCase):
def test_plus(self):
self.assertEqual(arithmetic(3, 4, '+'), 7)
def test_minus(self):
self.assertEqual(arithmetic(3, 4, '-'), -1)
def test_multiply(self):
self.assertEqual(arithmetic(3, 4, '*'), 12)
def test_divide(self):
self.assertEqual(arithmetic(3, 4, '/'), 3 / 4)
def test_unknown(self):
self.assertEqual(arithmetic(3, 4, '.'), "Неизвестная операция")
if __name__ == "__main__":
unittest.main()