diff --git a/system_check.py b/system_check.py index 6c19688..c8251d5 100644 --- a/system_check.py +++ b/system_check.py @@ -18,7 +18,9 @@ def get_departure_airport(ticket_string: str): Flight Number (JO234) can vary in length. You must find it relative to the hyphens. """ # TODO: Write your code here - pass + ticket_string = ticket_string.strip().split("-") + code = ticket_string[2] + return code def check_baggage_allowance(ticket_string: str): """ @@ -36,7 +38,14 @@ def check_baggage_allowance(ticket_string: str): - For any other code: return "Standard - 0kg" """ # TODO: Write your code here - pass + if ticket_string.startswith("EC"): + return "Economy - 20kg" + elif ticket_string.startswith("BS"): + return "Business - 40kg" + elif ticket_string.startswith("FL"): + return "First Class - 60kg" + else: + return "Standard - 0kg" def validate_flight_number(ticket_string: str): """ @@ -50,7 +59,17 @@ def validate_flight_number(ticket_string: str): - If the numeric part cannot be converted to a number, return "Invalid Flight" """ # TODO: Write your code here - pass + ticket_string = ticket_string.strip().split("-") + flight_info = ticket_string[1] + checker = int(flight_info[-1]) + + if checker % 2 == 0: + return "Valid - Northbound" + if checker % 2 != 0: + return "Valid - Southbound" + else: + return "Invalid flight" #probably had to use exceptions somewhere here + # ========================================== @@ -72,7 +91,12 @@ def is_leap_year(year: int): Return True or False (Boolean). """ # TODO: Write your code here - pass + if year % 400 == 0: + if year % 100 == 0: + if year % 4 == 0: + return True + return False + # ========================================== @@ -105,4 +129,16 @@ def reactor_status(temp: int, radiation: int): - For all other cases: return "Normal Operation" """ # TODO: Write your code here - pass + if temp < 500: + return "Maintenance Mode" + elif temp < 0 or radiation < 0: + return "Sensor Error" + elif temp > 2000 or radiation > 500: + return "CRITICAL" + elif 1000 < temp < 2000 and radiation > 100: + return "WARNING" + else: + return "Normal Mode" + + + diff --git a/test_reactor.py b/test_reactor.py new file mode 100644 index 0000000..7887187 --- /dev/null +++ b/test_reactor.py @@ -0,0 +1,35 @@ +import unittest +from system_check import reactor_status + + + +class TestReactor (unittest.TestCase): + def test_normal_sensors(self): + self.assertEqual(reactor_status(501,80), "Normal operation") + + def test_invalid_sensors(self): + self.assertEqual(reactor_status(-1, -5), "Sensor Error") + self.assertEqual(reactor_status(-10, 2), "Sensor Error") + self.assertEqual(reactor_status(1,-5), "Sensor Error") + + def test_critical_sensors(self): + self.assertEqual(reactor_status(2000, 502), "CRITICAL") + self.assertEqual(reactor_status(2500, 501), "CRITICAL") + self.assertEqual(reactor_status(2001,504), "CRITICAL") + + def test_unstable_sensors(self): + self.assertEqual(reactor_status(1500, 200), "WARNING") + self.assertEqual(reactor_status(2000, 500), "WARNING") + self.assertEqual(reactor_status(1000,150), "WARNING") + + def test_maintenance_mode(self): + self.assertEqual(reactor_status(400, 100), "Maintenance Mode") + self.assertEqual(reactor_status(490, 70), "Maintenance Mode") + self.assertEqual(reactor_status(100, 50), "Maintenance Mode") + + + +if __name__ == '__main__': + unittest.main() + + \ No newline at end of file