Adding chapter 5 source code
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
# test_mycalc_add.py test suite for add class method
|
||||
|
||||
import unittest
|
||||
from test_mycalc_add import MyCalcAddTestSuite
|
||||
from test_mycalc_subtract import MyCalcSubtractTestSuite
|
||||
from test_mycalc_multiply import MyCalcMultiplyTestSuite
|
||||
from test_mycalc_divide import MyCalcDivideTestSuite
|
||||
|
||||
def run_mytests():
|
||||
test_classes = [MyCalcAddTestSuite, MyCalcSubtractTestSuite,
|
||||
MyCalcMultiplyTestSuite,MyCalcDivideTestSuite ]
|
||||
|
||||
loader = unittest.TestLoader()
|
||||
|
||||
test_suites = []
|
||||
for t_class in test_classes:
|
||||
suite = loader.loadTestsFromTestCase(t_class)
|
||||
test_suites.append(suite)
|
||||
|
||||
final_suite = unittest.TestSuite(test_suites)
|
||||
|
||||
runner = unittest.TextTestRunner()
|
||||
results = runner.run(final_suite)
|
||||
#print(results)
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_mytests()
|
||||
@@ -0,0 +1,16 @@
|
||||
# test_mycalc_add.py test suite for add class method
|
||||
import unittest
|
||||
from myunittest.src.mycalc.mycalc import MyCalc
|
||||
|
||||
|
||||
class MyCalcAddTestSuite(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.calc = MyCalc()
|
||||
|
||||
def test_add(self):
|
||||
""" test case to validate two positive numbers"""
|
||||
self.assertEqual(15, self.calc.add(10, 5), "should be 15")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,15 @@
|
||||
#test_mycalc_divide.py test suite for divide class method
|
||||
import unittest
|
||||
from myunittest.src.mycalc.mycalc import MyCalc
|
||||
|
||||
class MyCalcDivideTestSuite(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.calc = MyCalc()
|
||||
|
||||
def test_divide(self):
|
||||
""" test case to validate two positive numbers"""
|
||||
self.assertEqual(2, self.calc.divide(10 , 5), "should be 2")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#test_mycalc_multiply.py test suite for multiply class method
|
||||
import unittest
|
||||
from myunittest.src.mycalc.mycalc import MyCalc
|
||||
|
||||
class MyCalcMultiplyTestSuite(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.calc = MyCalc()
|
||||
|
||||
def test_multiply(self):
|
||||
""" test case to validate two positive numbers"""
|
||||
self.assertEqual(50, self.calc.multiply(10 , 5), "should be 50")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#test_mycalc_subtract.py test suite for substract class method
|
||||
import unittest
|
||||
from myunittest.src.mycalc.mycalc import MyCalc
|
||||
|
||||
class MyCalcSubtractTestSuite(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.calc = MyCalc()
|
||||
|
||||
def test_subtract(self):
|
||||
""" test case to validate two positive numbers"""
|
||||
self.assertEqual(5, self.calc.subtract(10 , 5), "should be 5")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user