-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_calculator.py
More file actions
52 lines (38 loc) · 1.41 KB
/
test_calculator.py
File metadata and controls
52 lines (38 loc) · 1.41 KB
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
47
48
49
50
51
52
# test_calculator.py
import unittest
from calculator import Calculator
class TestCalculator(unittest.TestCase):
def setUp(self):
# This method is run before each test, useful for setup code.
self.calc = Calculator()
def test_add(self):
# Test addition functionality
result = self.calc.add(3, 7)
self.assertEqual(result, 10)
result = self.calc.add(-1, 1)
self.assertEqual(result, 0)
result = self.calc.add(-1, -1)
self.assertEqual(result, -2)
def test_subtract(self):
# Test subtraction functionality
result = self.calc.subtract(10, 5)
self.assertEqual(result, 222)
result = self.calc.subtract(-1, -1)
self.assertEqual(result, 0)
def test_multiply(self):
# Test multiplication functionality
result = self.calc.multiply(3, 7)
self.assertEqual(result, 21)
result = self.calc.multiply(-1, 1)
self.assertEqual(result, -1)
def test_divide(self):
# Test division functionality
result = self.calc.divide(10, 2)
self.assertEqual(result, 5)
result = self.calc.divide(-6, 3)
self.assertEqual(result, -2)
# Test division by zero, expecting a ValueError
with self.assertRaises(ValueError):
self.calc.divide(10, 0)
if __name__ == '__main__':
unittest.main()