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
52 lines (42 loc) · 1.58 KB
/
test_calculator.py
File metadata and controls
52 lines (42 loc) · 1.58 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
import unittest
from calculator import Calculator
class TestCalculator(unittest.TestCase):
def setUp(self):
self.calc = Calculator()
def test_add1(self):
self.assertEqual(self.calc.add(1, 1), 2)
def test_add2(self):
self.assertEqual(self.calc.add(-1, 1), 0)
def test_add3(self):
self.assertEqual(self.calc.add(-1, -1), -2)
def test_sub1(self):
self.assertEqual(self.calc.subtract(1, 1), 0)
def test_sub2(self):
self.assertEqual(self.calc.subtract(-1, 1), -2)
def test_sub3(self):
self.assertEqual(self.calc.subtract(-1, -1), 0)
def test_mul1(self):
self.assertEqual(self.calc.multiply(10, 3), 30)
def test_mul2(self):
self.assertEqual(self.calc.multiply(10, 0), 0)
def test_mul3(self):
self.assertEqual(self.calc.multiply(-10, -3), 30)
def test_div1(self):
self.assertEqual(self.calc.divide(10, 2), 5)
def test_div2(self):
with self.assertRaises(ZeroDivisionError):
self.calc.divide(10, 0)
def test_div3(self):
self.assertEqual(self.calc.divide(10, -2), -5)
def test_mod1(self):
self.assertEqual(self.calc.modulo(10, 3), 1)
def test_mod2(self):
with self.assertRaises(ZeroDivisionError):
self.calc.modulo(10, 0)
def test_mod3(self):
self.assertEqual(self.calc.modulo(-10, 3), 2)
def test_mod4(self):
self.assertEqual(self.calc.modulo(10, -3), -2)
# Add the following test methods to the TestCalculator class:
if __name__ == '__main__':
unittest.main()