forked from MUICT-SERU/python-calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_calculator.py
More file actions
42 lines (29 loc) · 1.14 KB
/
test_calculator.py
File metadata and controls
42 lines (29 loc) · 1.14 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
import unittest
from calculator import Calculator
class TestCalculator(unittest.TestCase):
def setUp(self):
self.calc = Calculator()
def test_add_positive(self):
self.assertEqual(self.calc.add(1, 2), 3)
def test_add_negative(self):
self.assertEqual(self.calc.add(-1, -2), -3)
def test_subtract_positive(self):
self.assertEqual(self.calc.subtract(5, 3), 2)
def test_subtract_negative(self):
self.assertEqual(self.calc.subtract(-5, -3), -2)
def test_multiply_positive(self):
self.assertEqual(self.calc.multiply(3, 4), 12)
def test_multiply_with_zero(self):
self.assertEqual(self.calc.multiply(3, 0), 0)
def test_divide_positive(self):
self.assertEqual(self.calc.divide(10, 2), 5)
def test_divide_by_zero(self):
with self.assertRaises(ZeroDivisionError):
self.calc.divide(5, 0)
def test_modulo_positive(self):
self.assertEqual(self.calc.modulo(10, 3), 1)
def test_modulo_by_zero(self):
with self.assertRaises(ZeroDivisionError):
self.calc.modulo(5, 0)
if __name__ == '__main__':
unittest.main()