Skip to content

Commit

Permalink
Add CA4 second question
Browse files Browse the repository at this point in the history
  • Loading branch information
PashaBarahimi committed Nov 28, 2023
1 parent 430197a commit 87af8b0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Binary file modified Baloot1/Reports/CA4.docx
Binary file not shown.
6 changes: 6 additions & 0 deletions Baloot1/Reports/Extras/CA4/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def calculate_total_cost(quantity, unit_price, discount):
if quantity <= 0 or unit_price <= 0:
return "Invalid input"
else:
total_cost = quantity * unit_price * (1 - discount)
return total_cost
41 changes: 41 additions & 0 deletions Baloot1/Reports/Extras/CA4/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import unittest

from main import calculate_total_cost

INVALID_INPUT = "Invalid input"

A = [-1, 0, 1, 2]
B = [-1, 0, 1]
C = [-1, 0, 0.5, 1, 2]


class TestCalculateTotalCost(unittest.TestCase):
def test_invalid_inputs_should_fail(self):
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[0], B[0], C[0]))
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[0], B[2], C[1]))
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[0], B[1], C[2]))
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[0], B[0], C[3]))
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[0], B[0], C[4]))
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[1], B[1], C[0]))
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[1], B[0], C[1]))
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[1], B[2], C[2]))
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[1], B[1], C[3]))
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[1], B[1], C[4]))
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[2], B[1], C[1]))
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[2], B[0], C[2]))
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[3], B[0], C[0]))
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[3], B[1], C[4]))

def test_invalid_discount_should_fail(self): # This case is not covered in the main.py
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[2], B[2], C[0]))
self.assertEqual(INVALID_INPUT, calculate_total_cost(A[2], B[2], C[4]))

def test_valid_inputs_should_pass(self):
self.assertEqual(0, calculate_total_cost(A[2], B[2], C[3]))
self.assertEqual(2, calculate_total_cost(A[3], B[2], C[1]))
self.assertEqual(1, calculate_total_cost(A[3], B[2], C[2]))
self.assertEqual(0, calculate_total_cost(A[3], B[2], C[3]))


if __name__ == '__main__':
unittest.main()

0 comments on commit 87af8b0

Please sign in to comment.