Adding chapter 5 source code

This commit is contained in:
muassif
2021-02-21 21:40:34 +04:00
committed by GitHub
parent e8469ec365
commit e662762d09
24 changed files with 348 additions and 0 deletions
@@ -0,0 +1 @@
#empty file
@@ -0,0 +1,24 @@
#test_myadd1.py test suite for myadd function
import unittest
from myunittest.src.myadd.myadd import add
class MyAddTestSuite(unittest.TestCase):
def test_add1(self):
""" test case to validate two positive numbers"""
self.assertEqual(15, add(10 , 5), "should be 15")
def test_add2(self):
""" test case to validate positive and negative numbers"""
self.assertEqual(5, add(10 , -5), "should be 5")
def test_add3(self):
""" test case to validate positive and negative numbers"""
self.assertEqual(-5, add(-10 , 5), "should be -5")
def test_add4(self):
""" test case to validate two negative numbers"""
self.assertEqual(-15, add(-10 , -5), "should be -15")
if __name__ == '__main__':
unittest.main()
@@ -0,0 +1,30 @@
#test_myadd2.py test suite for myadd2 class method
import unittest
from myunittest.src.myadd.myadd2 import MyAdd
class MyAddTestSuite(unittest.TestCase):
def setUp(self):
self.myadd = MyAdd()
def tearDown(self):
del (self.myadd)
def test_add1(self):
""" test case to validate two positive numbers"""
self.assertEqual(15, self.myadd.add(10 , 5), "should be 15")
def test_add2(self):
""" test case to validate positive and negative numbers"""
self.assertEqual(5, self.myadd.add(10 , -5), "should be 5")
def test_add3(self):
""" test case to validate positive and negative numbers"""
self.assertEqual(-5, self.myadd.add(-10 , 5), "should be -5")
def test_add4(self):
""" test case to validate two negative numbers"""
self.assertEqual(-15, self.myadd.add(-10 , -5), "should be -15")
if __name__ == '__main__':
unittest.main()
@@ -0,0 +1,19 @@
#test_myadd3.py test suite for myadd2 class method to validate errors
import unittest
from myunittest.src.myadd.myadd2 import MyAdd
class MyAddTestSuite(unittest.TestCase):
def setUp(self):
self.myadd = MyAdd()
def test_typeerror1(self):
""" test case to check if we can handle non number input"""
self.assertRaises(TypeError, self.myadd.add, 'a' , -5)
def test_typeerror2(self):
""" test case to check if we can handle non number input"""
self.assertRaises(TypeError, self.myadd.add, 'a' , 'b')
if __name__ == '__main__':
unittest.main()