-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_main.py
More file actions
32 lines (22 loc) · 848 Bytes
/
Copy pathtest_main.py
File metadata and controls
32 lines (22 loc) · 848 Bytes
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
import unittest
from main import Calculator
class TestCalculator(unittest.TestCase):
def setUp(self):
self.calc = Calculator()
def test_add(self):
self.assertEqual(self.calc.add(2, 3), 5)
self.assertEqual(self.calc.add(-1, 1), 0)
def test_subtract(self):
self.assertEqual(self.calc.subtract(10, 4), 6)
self.assertEqual(self.calc.subtract(0, 5), -5)
def test_multiply(self):
self.assertEqual(self.calc.multiply(3, 4), 12)
self.assertEqual(self.calc.multiply(0, 100), 0)
def test_divide(self):
self.assertEqual(self.calc.divide(10, 2), 5.0)
self.assertEqual(self.calc.divide(9, 3), 3.0)
def test_divide_by_zero(self):
with self.assertRaises(ValueError):
self.calc.divide(5, 0)
if __name__ == "__main__":
unittest.main()