Skip to content

Commit b92f49d

Browse files
author
Psudopodiya
authored
Added the test cases for add, sub, div, milt, mod definitions (#41)
* Added the test cases for add, sub, div, milt, mod definations * Changed the name fo file to TestBasicMath
1 parent 0315c4c commit b92f49d

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

easyPythonpi/TestBasicMath.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import unittest
2+
import easyPythonpi
3+
4+
class TestBasicMath(unittest.TestCase):
5+
6+
def test_add_positive_numbers(self):
7+
self.assertEqual(easyPythonpi.add(2, 3), 5)
8+
9+
def test_add_negative_numbers(self):
10+
self.assertEqual(easyPythonpi.add(-1, 1), 0)
11+
12+
def test_add_with_zero(self):
13+
self.assertEqual(easyPythonpi.add(0.5, 0.5), 1.0)
14+
15+
def test_subtract_positive_numbers(self):
16+
self.assertEqual(easyPythonpi.sub(5, 2), 3)
17+
18+
def test_subtract_with_zero(self):
19+
self.assertEqual(easyPythonpi.sub(0, 0), 0)
20+
21+
def test_subtract_negative_numbers(self):
22+
self.assertEqual(easyPythonpi.sub(-1, -1), 0)
23+
24+
def test_multiply_positive_numbers(self):
25+
self.assertEqual(easyPythonpi.multi(3, 4), 12)
26+
27+
def test_multiply_by_zero(self):
28+
self.assertEqual(easyPythonpi.multi(0, 5), 0)
29+
30+
def test_multiply_by_negative_numbers(self):
31+
self.assertEqual(easyPythonpi.multi(-2, 6), -12)
32+
33+
def test_divide_by_smaller_number(self):
34+
self.assertEqual(easyPythonpi.div(6, 2), 3.0)
35+
36+
def test_divide_zero_by_number(self):
37+
self.assertEqual(easyPythonpi.div(0, 5), 0.0)
38+
39+
def test_divide_by_zero_raises_exception(self):
40+
with self.assertRaises(ZeroDivisionError):
41+
easyPythonpi.div(5, 0)
42+
43+
def test_mod_positive_numbers(self):
44+
self.assertEqual(easyPythonpi.mod(7, 3), 1)
45+
self.assertEqual(easyPythonpi.mod(10, 2), 0)
46+
47+
def test_mod_zero(self):
48+
self.assertEqual(easyPythonpi.mod(0, 5), 0)
49+
50+
def test_mod_divide_by_zero(self):
51+
with self.assertRaises(ZeroDivisionError):
52+
easyPythonpi.mod(8, 0)
53+
54+
55+
if __name__ == '__main__':
56+
unittest.main()
5.38 KB
Binary file not shown.

0 commit comments

Comments
 (0)