-
Notifications
You must be signed in to change notification settings - Fork 15
test #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
test #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| return "Invalid flight" #probably had to use exceptions somewhere here | |
| return "Invalid Flight" #probably had to use exceptions somewhere here |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
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'.
| 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
AI
Nov 28, 2025
There was a problem hiding this comment.
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.
| 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
AI
Nov 28, 2025
There was a problem hiding this comment.
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.
| 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
AI
Nov 28, 2025
There was a problem hiding this comment.
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.
| elif 1000 < temp < 2000 and radiation > 100: | |
| elif 1000 <= temp <= 2000 and radiation > 100: |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
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'.
| return "Normal Mode" | |
| return "Normal Operation" |
| 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): | ||||||
|
||||||
| class TestReactor (unittest.TestCase): | |
| class TestReactor(unittest.TestCase): |
There was a problem hiding this comment.
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 whenint(flight_info[-1])fails for non-numeric characters.