Skip to content

Commit 2f0e851

Browse files
committed
Practical week 9 2024-2025
1 parent 8ffa34d commit 2f0e851

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

mathmanager.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,45 @@ def subtract(self, a, b):
88

99
def multiply(self, a, b):
1010
return a*b
11+
12+
def interest(self, deposit, term):
13+
if deposit <= 0:
14+
return -1
15+
if term == 1:
16+
return (0.038*deposit)/12
17+
elif term == 2:
18+
return (0.036*deposit)/12
19+
else:
20+
return -2
21+
22+
def tax(self, income):
23+
if (income >= 0 and income <= 12570):
24+
return 0
25+
elif (income > 12570 and income <= 50270):
26+
return 20/100*(income-12570)
27+
elif (income >50270 and income <= 125140):
28+
return 20/100*(50270-12570) + 40/100*(income-50270)
29+
elif (income > 125140):
30+
return 20/100*(50270-12570) + 40/100*(125140-50270) + 45/100*(income-125140)
31+
else:
32+
return -1
33+
34+
35+
def degree(self, fyp, comp1, comp2, opt1, opt2):
36+
if (fyp < 0 or comp1 < 0 or comp2 <0 or opt1 < 0 or opt2 < 0):
37+
return -1
38+
if (fyp > 100 or comp1 > 100 or comp2 > 100 or opt1 > 100 or opt2 > 100):
39+
return -1
40+
m = min(comp1, comp2, opt1, opt2)
41+
avg = (fyp + comp1 + comp2 + opt1 + opt2 - m) / 4
42+
if avg >=70:
43+
return "first"
44+
elif (avg < 70 and avg >= 60):
45+
return "2:1"
46+
elif (avg < 60 and avg >= 50):
47+
return "2:2"
48+
elif (avg < 50 and avg >= 40):
49+
return "third"
50+
else:
51+
return "fail"
52+

mathmanagertest.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,65 @@ def testSubtract(self):
1313
def testMultiply(self):
1414
math = mathmanager()
1515
self.assertEqual(math.multiply(0, 3), 0)
16+
17+
def testInterest(self):
18+
math = mathmanager()
19+
self.assertEqual(round(math.interest(1000, 1)), 3)
20+
21+
#Interest rate
22+
#positive amount, term = 2
23+
def testInterest1(self):
24+
math = mathmanager()
25+
self.assertEqual(math.interest(1000, 2), 3)
26+
27+
#positive amount, term = 3 (invalid)
28+
def testInterest2(self):
29+
math = mathmanager()
30+
self.assertEqual(math.interest(1000, 3), -2)
31+
32+
#negative amount, term = 1
33+
def testInterest3(self):
34+
math = mathmanager()
35+
self.assertEqual(math.interest(-1000, 1), -1)
36+
37+
#add: positive amount, term = 1, 3, 0, -1
38+
# negative amount, term = 2, -1, 0, 3
39+
# zero amount, term = 1, 2, 3, 0, -1
40+
41+
42+
#Tax calculator
43+
#income in first bracket
44+
def testTax(self):
45+
math = mathmanager()
46+
self.assertEqual(math.tax(10000), 0)
47+
48+
#income in second bracket
49+
def testTax1(self):
50+
math = mathmanager()
51+
self.assertEqual(math.tax(15000), 486)
52+
53+
#income in third bracket
54+
def testTax2(self):
55+
math = mathmanager()
56+
self.assertEqual(math.tax(52000), 8232)
57+
58+
#add income in all brackets, negative income, income equals each threashold
59+
60+
61+
#Degree classification calculator
62+
#combination of grades that get a 2:1
63+
def testDegree(self):
64+
math = mathmanager()
65+
self.assertEqual(math.degree(40, 70, 70, 55, 60), "2:1")
66+
67+
#combination of grades that get a third
68+
def testDegree1(self):
69+
math = mathmanager()
70+
self.assertEqual(math.degree(0, 70, 50, 60, 40), "third")
71+
72+
#at least one negative grade
73+
def testDegree2(self):
74+
math = mathmanager()
75+
self.assertEqual(math.degree(-1, 40, 40, 40, 40), -1)
76+
77+
#add at least one grade higher than 100, combination of grades that get a fist, 2:2, fail

0 commit comments

Comments
 (0)