Skip to content
Snippets Groups Projects
Commit 4f39246d authored by Nguyen5.Trung@live.uwe.ac.uk's avatar Nguyen5.Trung@live.uwe.ac.uk
Browse files

add week_11

parent 3b1c7091
Branches main
No related tags found
No related merge requests found
File added
File added
class Calculate:
def sum(a, b ):
return a +b
def multiply(a, b ):
return a * b
\ No newline at end of file
class Calculator:
def sum(a, b):
return a +b
def multiply(a, b):
return a * b
def subtract(a, b):
return a -b
def divide(a, b):
if b == 0:
raise ValueError("Division by zero is not allowed")
return a / b
import unittest
from my_sum import Calculator
class TestCalculator(unittest.TestCase):
def test_add(self):
self.assertEqual(Calculator.sum(2, 3), 5)
self.assertEqual(Calculator.sum(5, 7), 12)
self.assertEqual(Calculator.sum(-1, 1), 0)
self.assertEqual(Calculator.sum(-1, -1), -2)
self.assertEqual(Calculator.sum(0, 0), 0)
self.assertEqual(Calculator.sum(0, 1), 1)
def test_multiply(self):
self.assertEqual(Calculator.multiply(2, 3), 6)
self.assertEqual(Calculator.multiply(5, 7), 35)
self.assertEqual(Calculator.multiply(-1, 1), -1)
self.assertEqual(Calculator.multiply(-1, -1), 1)
self.assertEqual(Calculator.multiply(0, 0), 0)
def test_divide(self):
self.assertEqual(Calculator.divide(6, 2), 3)
self.assertEqual(Calculator.divide(10, 2), 5)
self.assertEqual(Calculator.divide(5, 1), 5)
self.assertEqual(Calculator.divide(0, 1), 0)
self.assertEqual(Calculator.divide(0, 2), 0)
def test_subtract(self):
self.assertEqual(Calculator.subtract(2, 3), -1)
self.assertEqual(Calculator.subtract(5, 7), -2)
self.assertEqual(Calculator.subtract(-1, 1), -2)
self.assertEqual(Calculator.subtract(-1, -1), 0)
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
import unittest
from cal import Calculate
class TestCalculate(unittest.TestCase):
def test_sum(self):
self.assertEqual(Calculate.sum(2, 3), 5)
self.assertEqual(Calculate.sum(5, 7), 12)
def test_multiply(self):
self.assertEqual(Calculate.multiply(2, 3), 6)
self.assertEqual(Calculate.multiply(5, 7), 35)
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
[["Zaheer Khan", "Prof", "3Q31", "zaheer2.khan@uwe.ac.uk"], ["Mehmet Aydin", "Senior Lecturer", "4Q59", "mehmet.aydin@uwe.ac.uk"], ["James Lear", "Lecturer", "4Q59", "james.lear@uwe.ac.uk"], ["Barkha Javed", "Lecturer", "3E40", "barkha.javed@uwe.ac.uk"], ["Elias Pimenides", "Senior Lecturer", "3Q31", "elias.pimenides@uwe.ac.uk"]]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment