Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions system_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand All @@ -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
Comment on lines +64 to +71
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unreachable else clause at line 70-71. Since line 68 checks checker % 2 != 0 (which covers all cases not covered by line 66), the else block will never execute. Additionally, line 71 returns 'Invalid flight' but should return 'Invalid Flight' (capital F) per the docstring. The function also doesn't handle the ValueError exception when int(flight_info[-1]) fails for non-numeric characters.

Suggested change
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
try:
checker = int(flight_info[-1])
except ValueError:
return "Invalid Flight"
if checker % 2 == 0:
return "Valid - Northbound"
else:
return "Valid - Southbound"

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return value has incorrect capitalization. Should be 'Invalid Flight' (capital F) to match the specification in the function docstring at line 59.

Suggested change
return "Invalid flight" #probably had to use exceptions somewhere here
return "Invalid Flight" #probably had to use exceptions somewhere here

Copilot uses AI. Check for mistakes.
Comment on lines +64 to +71
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing exception handling for invalid input. Line 64 will raise a ValueError if the last character of flight_info is not numeric (e.g., 'JOABC'), but this exception is not caught. According to the test at line 41 in test_system_check.py, 'FL-JOABC-JNB-CPT' should return 'Invalid Flight'. Wrap the int conversion in a try-except block to catch ValueError and return 'Invalid Flight'.

Suggested change
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
try:
checker = int(flight_info[-1])
except ValueError:
return "Invalid Flight"
if checker % 2 == 0:
return "Valid - Northbound"
if checker % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"

Copilot uses AI. Check for mistakes.



# ==========================================
Expand All @@ -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
Comment on lines +95 to +98
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leap year logic is inverted. The correct implementation should check divisibility by 4 first, then 100, then 400. A year divisible by 400 is always a leap year (e.g., 2000), but the current nested logic will fail for years like 2024 (divisible by 4 but not 400). The function should be: if divisible by 400, return True; elif divisible by 100, return False; elif divisible by 4, return True; else return False.

Suggested change
if year % 100 == 0:
if year % 4 == 0:
return True
return False
return True
elif year % 100 == 0:
return False
elif year % 4 == 0:
return True
else:
return False

Copilot uses AI. Check for mistakes.



# ==========================================
Expand Down Expand Up @@ -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"
Comment on lines +132 to +135
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic order error: checking temp < 500 before temp < 0 means negative temperatures will incorrectly return 'Maintenance Mode' instead of 'Sensor Error'. The sensor error check (line 134-135) must come first to properly handle negative values.

Suggested change
if temp < 500:
return "Maintenance Mode"
elif temp < 0 or radiation < 0:
return "Sensor Error"
if temp < 0 or radiation < 0:
return "Sensor Error"
elif temp < 500:
return "Maintenance Mode"

Copilot uses AI. Check for mistakes.
elif temp > 2000 or radiation > 500:
return "CRITICAL"
elif 1000 < temp < 2000 and radiation > 100:
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect range check excludes boundary values. According to the docstring specifying 'between 1000 and 2000 (inclusive)', this should be 1000 <= temp <= 2000 to include both boundaries.

Suggested change
elif 1000 < temp < 2000 and radiation > 100:
elif 1000 <= temp <= 2000 and radiation > 100:

Copilot uses AI. Check for mistakes.
return "WARNING"
else:
return "Normal Mode"
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect return value. According to the docstring and test expectations (line 59 in test_system_check.py expects 'Normal Operation'), this should return 'Normal Operation' not 'Normal Mode'.

Suggested change
return "Normal Mode"
return "Normal Operation"

Copilot uses AI. Check for mistakes.



35 changes: 35 additions & 0 deletions test_reactor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest
from system_check import reactor_status



class TestReactor (unittest.TestCase):
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space before parenthesis in class name. Should be TestReactor(unittest.TestCase): without the space.

Suggested change
class TestReactor (unittest.TestCase):
class TestReactor(unittest.TestCase):

Copilot uses AI. Check for mistakes.
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()