-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_calculator.py
32 lines (26 loc) · 1.08 KB
/
test_calculator.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
import unittest
from calculator import Calculator
class TestCalculator(unittest.TestCase):
def setUp(self):
self.calc = Calculator()
def test_add(self):
self.assertEqual(self.calc.add(1, 2), 3)
self.assertEqual(self.calc.add(-1, 1), 0)
self.assertEqual(self.calc.add(0, 0), 0)
def test_subtract(self):
self.assertEqual(self.calc.subtract(10, 5), 5)
self.assertEqual(self.calc.subtract(2, 3), -1)
self.assertEqual(self.calc.subtract(0, 0), 0)
def test_multiply(self):
self.assertEqual(self.calc.multiply(3, 4), 12)
self.assertEqual(self.calc.multiply(-1, 5), -5)
self.assertEqual(self.calc.multiply(0, 100), 0)
def test_divide(self):
self.assertEqual(self.calc.divide(10, 2), 5)
self.assertEqual(self.calc.divide(-10, 2), -5)
with self.assertRaises(ValueError):
self.calc.divide(10, 0)
with self.assertRaises(ValueError):
self.calc.divide(0, 0)
if __name__ == '__main__':
unittest.main()