Nirajj 1
Nirajj 1
Experiment 2
To write a test script using a unit testing framework for addition, subtraction, multiplication, and
division of two numbers.
Objective
Materials Required
import unittest
return a + b
return a - b
return a * b
return a / b
class TestArithmeticOperations(unittest.TestCase):
def test_add(self):
self.assertEqual(add(2, 3), 5)
self.assertEqual(add(-1, 1), 0)
def test_subtract(self):
self.assertEqual(subtract(5, 3), 2)
def test_multiply(self):
def test_divide(self):
self.assertEqual(divide(6, 3), 2)
with self.assertRaises(ValueError):
divide(6, 0)
if __name__ == '__main__':
unittest.main()
Observations
Conclusion
● Summarize the results of the experiment. State whether all test cases passed and if the arithmetic
functions behaved as expected.