Created
March 19, 2021 17:19
-
-
Save perryBunn/5257f9d0186e21b2679e9ea244ddb26b to your computer and use it in GitHub Desktop.
SQA Assignment 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(x, y) -> str: | |
under = { | |
1000: .03, | |
5000: .04, | |
20000: .05 | |
} | |
over = { | |
1000: .02, | |
5000: .03, | |
20000: .04 | |
} | |
try: | |
res = "" | |
print(f"\nInput: X={x}, Y={y}") | |
case_1 = x != 0 | |
case_2 = x != 1 | |
if case_2 and case_1: | |
raise TypeError | |
if x: | |
print("Over 25") | |
for x in over: | |
if y >= x: | |
res = f"Insurance rate is: {over[x]} of {round(y, 2)}" | |
res += f"\n= ${round(y * over[x], 2)}" | |
else: | |
print("Under 25") | |
for x in under: | |
if y >= x: | |
res = f"Insurance rate is: {under[x]} of {round(y, 2)}" | |
res += f"\n= ${round(y*under[x], 2)}" | |
if res == "": | |
res = "This car can not be insured. Min insured cost is $1000." | |
print(res) | |
return res | |
except TypeError: | |
print("Invalid input") | |
return "Invalid input" | |
if __name__ == '__main__': | |
main(1, 999.99) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from assignment5 import main | |
class MyTestCase(unittest.TestCase): | |
def test_invalid(self): | |
res = main(1324, 19489.33436) | |
should_be = "Invalid input" | |
self.assertEqual(res, should_be) | |
def test_under_uninsure(self): | |
res = main(0, 999.99999) | |
should_be = "This car can not be insured. Min insured cost is $1000." | |
self.assertEqual(res, should_be) | |
def test_under_onek(self): | |
res = main(0, 1234.2353) | |
should_be = "Insurance rate is: 0.03 of 1234.24\n= $37.03" | |
self.assertEqual(res, should_be) | |
def test_under_fivek(self): | |
res = main(0, 5293.2384) | |
should_be = "Insurance rate is: 0.04 of 5293.24\n= $211.73" | |
self.assertEqual(res, should_be) | |
def test_under_twentyk(self): | |
res = main(0, 209348.9328467) | |
should_be = "Insurance rate is: 0.05 of 209348.93\n= $10467.45" | |
self.assertEqual(res, should_be) | |
def test_over_onek(self): | |
res = main(1, 1234.2353) | |
should_be = "Insurance rate is: 0.02 of 1234.24\n= $24.68" | |
self.assertEqual(res, should_be) | |
def test_over_fivek(self): | |
res = main(1, 5293.2384) | |
should_be = "Insurance rate is: 0.03 of 5293.24\n= $158.8" | |
self.assertEqual(res, should_be) | |
def test_over_twentyk(self): | |
res = main(1, 209348.9328467) | |
should_be = "Insurance rate is: 0.04 of 209348.93\n= $8373.96" | |
self.assertEqual(res, should_be) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment